Ping in Python

Fredrik Lundh fredrik at pythonware.com
Thu Jan 13 03:08:07 EST 2000


Anders M Eriksson wrote:
> Everyday about 1.30 pm my Intenet just dies. Everything takes forever
> and IE nearly almost will TimeOut on all pages. So I need to test and
> document this so I can tell my ISP that there is something wrong.
> 
> So I thought: Why don't I create an Python program that will PING a
> list of hosts and log the response! 
> 
> But how does a PING work?

it sends a low-level ICMP package; you have
to open the socket as SOCK_RAW, and build
the package yourself.

(and on a Unix box, your program needs to
run as root...)

it's probably easiest to run an external ping
utility and parse the output.  lots of people
have written ping wrappers; searching the
newsgroup [1] for "ping command" or "ping"
should help you find most of them:

and if you insist, Jeremy Hylton has ping and
traceroute code at:
    http://the-tech.mit.edu/~jeremy/python/

</F>

[1] www.python.org -> search -> newsgroup

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list