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

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

有任何想法吗?

最佳答案

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

>>> 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

关于python - 测量服务器的ping延迟-Python,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2525312/

10-10 20:48