current position:Home>Python problem Ping

Python problem Ping

2022-07-25 11:18:26CSDN Q & A

python By calling ping command , Judge liansuodian LAN in the list ip Whether the address is connected , If it works , Get delay information 、 Packet loss information 、 Average delay and other related return information , And by judging the delay time , The delay time exceeds 10 Second warning , Take out the negative alert information and give it a list value . If it doesn't work, it doesn't work ip Address , Pay an address to a list . every other 10 The automatic cycle is executed every minute .
I wrote it now , If more than one doesn't work , Only the first one can extract ip Address , Then it jumps out of the loop , How can I write it to meet the needs I put forward above . Please point out. thank you , Be deeply grateful

# *--coding=utf-8--*import osimport subprocessimport reimport content as contentfrom pythonping import pingliansuodian = ['193.168.46.254','193.168.46.115','193.168.13.254','193.168.16.254','172.16.10.44']for i in liansuodian:    command = os.popen("ping -n 1 " + i)    pin = command.read()    # print(pin)    if " request timeout " in pin:        p = i        print(p)        # print("NO")    else:        bytime = re.findall(r' Time =(\w)', pin, re.M)        print(bytime)

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/206/202207181917172201.html

Random recommended