php - 如何测试ip响应时间,可以设置毫秒级超时?
学习ing
学习ing 2017-06-07 09:23:00
0
1
883

我要测试一批ip响应时间,类似ping的响应时间,要求毫秒级的。
可以设置毫秒级超时,如 >500ms 就为不合格,继续测试下一个。
Python、PHP脚本都可以

学习ing
学习ing

全部回复(1)
世界只因有你
#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'

记得给赞哟

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!