python - Pinging Ip's and returning up/down status AND latency -


i using python , using method this

def ping(host): # ping parameters function of os parameters = "-n 1" if system_name().lower()=="windows" else "-c 1"  # pinging return system_call("ping " + parameters + " " + host) == 0 

to up/down status of list of ip's pinging. there way extract latency well?

my output when running code looks along lines of

ping statistics x.x.x.x: packets: sent = 1, received = 1, lost = 0 (0% loss), approximate round trip times in milli-seconds: minimum = 50ms, maximum = 50ms, average = 50ms x.x.x.x down 

i x.x.x.x down, latency = 50ms. there simple way overlooking?

you need use subprocess. docs on os.system:

changes sys.stdin, etc. not reflected in environment of executed command. if command generates output, sent interpreter standard output stream.

subprocess easier.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -