[ale] Py[h]hon syntax (sic)
John P. Healey
jpheale at LearnLink.Emory.Edu
Thu Jan 27 14:57:43 EST 2005
the code for pinging would look something like this:
import os
import re
def ping(ip, tries = 2):
my_re = re.compile('(\w|\W)+ (\d) received, (\w|\W)+')
for attempt in range(tries):
ping_in, ping_out = os.popen2("ping -c 1 %s" % ip)
for line in ping_out:
rec_match = my_re.match(line)
if not rec_match: continue
received = int(rec_match.groups()[1])
if not received: continue
return attempt + 1
return False
it takes an optional second argument (# of tries) and returns the number of
tries needed when successful, False otherwise. the SMTP stuff can be handled
with smtplib. it's part of the standard library. the main python site has
pretty good documentation on this, including example code:
http://docs.python.org/lib/module-smtplib.html
5265762e204a6f686e6e79204865616c6579
More information about the Ale
mailing list