【发布时间】:2017-08-14 20:04:35
【问题描述】:
我正在使用 python,我正在使用这样的方法
def ping(host):
# Ping parameters as function of OS
parameters = "-n 1" if system_name().lower()=="windows" else "-c 1"
# Pinging
return system_call("ping " + parameters + " " + host) == 0
获取我正在 ping 的 ip 列表的向上/向下状态。有没有办法从中提取延迟?
运行此代码时我的输出看起来类似于
Ping statistics for x.x.x.x:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 50ms, Maximum = 50ms, Average = 50ms
x.x.x.x is down
我想说 x.x.x.x 已关闭,延迟 = 50 毫秒。有没有一种我忽略的简单方法?
【问题讨论】:
-
您必须解析
system_call的输出。那是什么功能?你定义了吗? -
from os import system as system_call -
我希望我不必解析输出。哦好吧哈哈。