php - 如何测试ip响应时间,可以设置毫秒级超时?
本文介绍了php - 如何测试ip响应时间,可以设置毫秒级超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
我要测试一批ip响应时间,类似ping的响应时间,要求毫秒级的。
可以设置毫秒级超时,如 >500ms 就为不合格,继续测试下一个。
Python、PHP脚本都可以
解决方案
#coding=utf8
import os
ip_list=['192.168.0.1','192.168.0.2','192.168.0.3','192.168.0.106']
for each in ip_list:
a=os.popen('ping -n 1 %s'%each).read().decode('gbk')
b=a.find('=')
c=a.find('ms')
time=a[b+7:c]
try:
if int(str(time))>=500:
print 'time >= 500ms'
else:
print each+' : '+time+'ms'
except Exception as e:
print 'lost'
记得给赞哟
这篇关于php - 如何测试ip响应时间,可以设置毫秒级超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文