Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

a simple netcat script

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
8 posts • Page 1 of 1
Author
Message
gothbox
n00b
n00b
User avatar
Posts: 15
Joined: Tue Mar 15, 2005 9:38 pm
Location: Norway

a simple netcat script

  • Quote

Post by gothbox » Tue Mar 02, 2010 9:29 pm

i need some help to put toghether a simple script to check if port 80 is open (netcat?)
# nc -z -v localhost 80
localhost [127.0.0.1] 80 (http) open

and if not , to start a script ...
something to set as a cron job maybe ?
im very new to programming , but this shouldnt be to hard ?

thanks alot :)
its only wrong if you get caught
Top
Naib
Watchman
Watchman
User avatar
Posts: 6103
Joined: Fri May 21, 2004 9:42 pm
Location: Removed by Neddy
Contact:
Contact Naib
Website

  • Quote

Post by Naib » Tue Mar 02, 2010 9:33 pm

if lsof -i :80 >/dev/null; then echo "port 80 in use"; fi
#define HelloWorld int
#define Int main()
#define Return printf
#define Print return
#include <stdio>
HelloWorld Int {
Return("Hello, world!\n");
Print 0;
Top
gothbox
n00b
n00b
User avatar
Posts: 15
Joined: Tue Mar 15, 2005 9:38 pm
Location: Norway

  • Quote

Post by gothbox » Tue Mar 02, 2010 9:40 pm

that didnt tell me to much to be honest , what does it do ?
i have a ssh session with tunnels running on my school computer , back home , and i need it to be restarted if either my home pc or school pc goes down..
i have no control from home , and would like the script to be restarted if my home computer goes down f,ex ..
its started each time the school pc boots
its only wrong if you get caught
Top
Naib
Watchman
Watchman
User avatar
Posts: 6103
Joined: Fri May 21, 2004 9:42 pm
Location: Removed by Neddy
Contact:
Contact Naib
Website

  • Quote

Post by Naib » Tue Mar 02, 2010 9:45 pm

it checks if port-80 is open (needs to be run by root since it is a priv port) and if it is prints that str to the screen
#define HelloWorld int
#define Int main()
#define Return printf
#define Print return
#include <stdio>
HelloWorld Int {
Return("Hello, world!\n");
Print 0;
Top
gothbox
n00b
n00b
User avatar
Posts: 15
Joined: Tue Mar 15, 2005 9:38 pm
Location: Norway

  • Quote

Post by gothbox » Tue Mar 02, 2010 9:59 pm

hahahahahahahaha!


i love you !!!

this is just what i want !


best wishes :)
its only wrong if you get caught
Top
Naib
Watchman
Watchman
User avatar
Posts: 6103
Joined: Fri May 21, 2004 9:42 pm
Location: Removed by Neddy
Contact:
Contact Naib
Website

  • Quote

Post by Naib » Tue Mar 02, 2010 10:04 pm

:)
#define HelloWorld int
#define Int main()
#define Return printf
#define Print return
#include <stdio>
HelloWorld Int {
Return("Hello, world!\n");
Print 0;
Top
Ant P.
Watchman
Watchman
Posts: 6920
Joined: Sat Apr 18, 2009 7:18 pm
Contact:
Contact Ant P.
Website

  • Quote

Post by Ant P. » Tue Mar 02, 2010 10:18 pm

This one's longer but it'll work without root:

Code: Select all

if netstat -tuna | grep ':80 .*LISTEN' > /dev/null; then
    # local port 80 is open
else
    # isn't
fi
Top
gothbox
n00b
n00b
User avatar
Posts: 15
Joined: Tue Mar 15, 2005 9:38 pm
Location: Norway

  • Quote

Post by gothbox » Tue Mar 02, 2010 11:45 pm

ill have a look at it :) thanks alot
its only wrong if you get caught
Top
Post Reply

8 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Authors
Gentoo is a trademark of the Gentoo Foundation, Inc. and of Förderverein Gentoo e.V.
The contents of this document, unless otherwise expressly stated, are licensed under the CC-BY-SA-4.0 license.
The Gentoo Name and Logo Usage Guidelines apply.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy