search

Home  >  Q&A  >  body text

php - How to test ip response time, can set millisecond timeout?

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

学习ing学习ing2760 days ago963

reply all(1)I'll reply

  • 世界只因有你

    世界只因有你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

    reply
    0
  • Cancelreply