[ale] Py[h]hon syntax (sic)

Christopher Fowler cfowler at outpostsentinel.com
Thu Jan 27 17:53:18 EST 2005


What I find interesting is that the regular expression in this code
seems to be for the whole line.  In perl '/(\d) received/' would have
been fine but when I reduced the expression in this code then it failed
to see the host as being up.


On Thu, 2005-01-27 at 14:49, John P. Healey wrote:
> 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
> 
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale



More information about the Ale mailing list