How to "ping" a host ? (hackers solution
Gillou
nospam at bigfoot.com
Wed Jan 9 14:16:33 EST 2002
OK,
I've done it by myself.
Quick and dirty but works for any user and Linux (and perhaps for other
unices including cygwin).
import popen2, string
def ping(host):
'''Simple ping to host or IP
returns 1 if succeeded otherwise 0
'''
outs, ins, errs = popen2.popen3('ping -n -c 1 -q %s' % host)
o = outs.readlines()
e = errs.readlines()
if len(e):
return 0
# Gets the count of received packets
if int(string.split(o[3])[3]) == 0:
return 0
return 1
"Gillou" <nospam at bigfoot.com> a écrit dans le message news:
a1c44a$31an$1 at norfair.nerim.net...
> Hi,
>
> I'm looking for a pythonic "ping" like module. Did not find (or search
> correctly ?) in the doc.
> I mean something (non blocking) that replies to "is there a live host
> connected at this IP address ?"
>
> Thanks in advance !
>
> --Gillou
>
>
>
More information about the Python-list
mailing list