Re: [Tutor] ping question...

Magnus Lycka magnus at thinkware.se
Tue Dec 9 11:40:44 EST 2003


Hi Laura,

Slaybaugh Laura J IHMD wrote:
> My first stab was a simple x=os.system('ping -n 1 <ipaddress>'),
> unfortunately whether or not I run this line against a computer with a
> request timed out response, x equals 0.  Which helps me not at all.  

Yes, the  return code will be 0 for ping regardless of
responses, unless you make a syntax error in your command etc.
You need to get the output from the ping command into Python
for analysis, rather than its return code.

Maybe this interactive example can give you some hints...

>>> import os
>>> ip = raw_input('IP? ')
IP? <something>
>>> result = os.popen('ping %s' % ip).read()
>>> print result
<something>
>>> print "time-out" in result
True

-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus at thinkware.se



More information about the Tutor mailing list