alan.gauld at freenet.co.uk
Sun Aug 14 17:34:08 CEST 2005
> import os
> ping = os.popen('ping -c 4 10.0.8.200')
> ping_result = ping.read()
> I assume I have to use Regular Expression to read the results,
You shouldn't need to. If I call ping I get somethjing like:
$ ping www.google.com
PING www.l.google.com (22.214.171.124): 56 data bytes
64 bytes from 126.96.36.199: icmp_seq=0 ttl=229 time=220 ms
64 bytes from 188.8.131.52: icmp_seq=1 ttl=229 time=188 ms
64 bytes from 184.108.40.206: icmp_seq=2 ttl=229 time=188 ms
So to read that I would just use the string.split() method to
break it into fields and the IP address is the 4th field
and the time 7th.
But it depends on what exactly you want to do with it.
If you do want a basic intro to regex you can try my tutorial
topic on them. It doesn't cover the deeper bits but gives
the 30% I use 70% of the time...
Author of the Learn to Program web tutor
More information about the Tutor