如何使用ip ping IP并仅获取Tk中的ms? [英] How to ping an ip and get only the ms in the Tk with Python?

查看:99
本文介绍了如何使用ip ping IP并仅获取Tk中的ms?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个可以连续ping一个IP并仅显示MS的tk应用程序,例如"10ms"

I want to make a little tk app that continuous ping an ip and only show the MS, like, "10ms"

我该怎么办?

推荐答案

如果要使用Windows ping,则必须从命令行解析输出.

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]

这篇关于如何使用ip ping IP并仅获取Tk中的ms?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆