测量服务器的ping延迟-Python [英] Measuring ping latency of a server - Python

查看:463
本文介绍了测量服务器的ping延迟-Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务器 IP地址的列表,我需要检查每个服务器是否在线以及等待时间有多长时间.

I have a list of server IP addresses, I need to check if each one is online and how long the latency is.

我还没有找到实现此目的的任何直接方法,并且在准确计算延迟方面似乎存在一些问题.

I haven't found any straight forward ways of implementing this, and there seems to be a few problems in calculating latency accurately.

有什么想法吗?

推荐答案

如果您已经习惯于解析字符串,则可以使用subprocess模块​​将要查找的数据获取为字符串,如下所示:

If you are already comfortable with parsing strings, you can use the subprocess module to get the data you are looking for into a string, like this:

>>> import subprocess
>>> p = subprocess.Popen(["ping.exe","www.google.com"], stdout = subprocess.PIPE)
>>> print p.communicate()[0]

Pinging www.l.google.com [209.85.225.99] with 32 bytes of data:

Reply from 209.85.225.99: bytes=32 time=59ms TTL=52
Reply from 209.85.225.99: bytes=32 time=64ms TTL=52
Reply from 209.85.225.99: bytes=32 time=104ms TTL=52
Reply from 209.85.225.99: bytes=32 time=64ms TTL=52

Ping statistics for 209.85.225.99:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 59ms, Maximum = 104ms, Average = 72ms

这篇关于测量服务器的ping延迟-Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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