Find out if a host is alive

Alex Martelli aleax at aleax.it
Sat Oct 4 12:04:24 EDT 2003


Anand Pillai wrote:

> I would like to add a feature to one of my network programs.
> The requirement is to find out if a server is alive by sending
> it requests. I know of the standard ICMP ping, and searched
> for python modules able to 'PING'. The only hit I got was Jeremy
> Hiltons ping package, written for Python 1.4, and it does not
> work with the latest Python versions (2.0 upwards).

http://pynms.sourceforge.net/ does appear to support ICMP, among
many other things, and to support Python 2.2 (I'd be quite amazed
if it worked with 2.2 and not with 2.3).

> Are there other ways of finding out (in a few lines of code)
> whether a server is alive, apart from the ICMP protocol?

If you know what services the server is supposed to be running,
sure.  If you have no idea whatsoever, no way.  It's quite
imaginable, for example, that a server does not serve ICMP
(doesn't WANT to be pinged nor tracerouted etc) but only,
strictly HTTP on port 80/TCP _period_.  If you know that, then
'pinging' the server is useless as a way to determine whether
the server 'is alive'; rather, you would try to bind a socket
to its TCP port 80, and, depending on your definition of "being
alive", might claim that just managing to bind that socket is
enough (or, you might try some short HTTP transaction on the
socket).

I've noticed an analogy between people wanting their programs
to check if "a server is alive" and ones wanting their programs
to check if "a file exists": the question they pose is rarely
the one they really need to get answered; for example, the
mere existence of a file is often of no real interest if the
program does not have permission to _read_ the file -- and
the mere "aliveness" of a host is often of no real interest
if the program does not have permission to _talk_ to the host
along at least one protocol that's of actual _use_...


Alex





More information about the Python-list mailing list