I want to test the response time of a batch of IPs, similar to the response time of ping, which requires milliseconds.
You can set a millisecond-level timeout. If >500ms, it is considered unqualified and continue to the next test.
Both Python and PHP scripts are acceptable
世界只因有你2017-06-07 09:25:00
#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'
Remember to like it