Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Check server status remotely with a perl script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Check server status remotely with a perl script
Authored by: pete_v on Feb 28, '06 01:22:38PM

why reinvent the wheel?

> nc $host $port

- see 'man nc' for more details

/Pete



[ Reply to This | # ]
Check server status remotely with a perl script
Authored by: mistersquid on Mar 01, '06 05:03:33AM

Pete, I appreciate your pointing to a standard UNIX utility to do this work, but your post reeks of programmer's laziness. Not only do you refer everyone to the "man" page for nc, but you provide no further details.

I'm moderately experienced issuing commands at the CLI, though I don't program in the shell. Like many, I program in PERL (or some other non-shell scripting language) and then execute from the command line. The beauty is I don't have to figure out the idiosyncrasies of every UNIX utility out there.

Would you mind explaining to those of us who do not program at the command line how one might use the functionality of nc to take some kind of action once a connection establishes or fails to establish?

From what I can tell, nc is interactive and the only way to do this as an automated task is to have a non-shell interface querying using nc.



[ Reply to This | # ]
Check server status remotely with a perl script
Authored by: foilpan on Mar 01, '06 11:00:42AM

i didn't interpret the previous post with any sort of hostility or "programmer's laziness," as you did.

since i'm not that familiar with netcat's usage, it took a minute or two of quick man page reading to see what it does. that's not so bad.

for instance, i just issued a <code>nc -vz 192.168.1.1 1-80</code> to scan the open ports on our main server here in the office (that's not the internal IP, but you get the idea). it works like a charm, showing which ports are open. If you try with a host that's down, it will report as such. neat-o.

i've used nmap to test for hosts' status, too.



[ Reply to This | # ]
Check server status remotely with a perl script
Authored by: rschwarz on Mar 01, '06 12:17:01PM
Thank you foilpan for your additional information on the usage of nc. Although I looked up the man page, it was not instantly clear to me, that this can be done so easily.

You can also set the timeout with the -w option. This is useful to me, since I don't want to wait a minute or so until netcat aborts.

[ Reply to This | # ]
left out stuff
Authored by: macubergeek on Mar 01, '06 03:42:47PM

you failed to mention that after you do nc whatever.com 80 you have to do
get /
to determine if it's live or not, or to at least pull the index.htm page.



[ Reply to This | # ]
Check server status remotely with a perl script
Authored by: gaoshan on Mar 05, '06 11:27:26PM
Doing nc and adding an extra -v or 2 for verbosity...i.e.
nc -vvvz 192.168.1.1 1-80
results in some pretty decent info. You get something like the following:
(UNKNOWN) [192.168.1.1] 80 (http) open
(UNKNOWN) [192.168.1.1] 79 (finger) : Connection refused
(UNKNOWN) [192.168.1.1] 78 (vettcp) : Connection refused
(UNKNOWN) [192.168.1.1] 77 (?) : Connection refused


[ Reply to This | # ]