问题
I want to make a little tk app that continuous ping an ip and only show the MS, like, "10ms"
how could I do?
回答1:
If you want to use Windows ping
, you'll have to parse the output from the command line.
This is very specific, but should work:
import os
while(1):
ping = os.popen('ping www.google.com -n 1')
result = ping.readlines()
msLine = result[-1].strip()
print msLine.splot(' = ')[-1]
回答2:
To continuously ping an IP
os.system("ping -t 192.168.1.1")
来源:https://stackoverflow.com/questions/2430519/how-to-ping-an-ip-and-get-only-the-ms-in-the-tk-with-python