How to ping an ip and get only the ms in the Tk with Python?

我的未来我决定 提交于 2019-12-10 10:38:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!