Python Function to test ping

前端 未结 5 1503
既然无缘
既然无缘 2020-12-09 08:59

I\'m trying to create a function that I can call on a timed basis to check for good ping and return the result so I can update the on-screen display. I am new to python so I

5条回答
  •  春和景丽
    2020-12-09 09:45

    This is my version of check ping function. May be if well be usefull for someone:

    def check_ping(host):
    if platform.system().lower() == "windows":
    response = os.system("ping -n 1 -w 500 " + host + " > nul")
    if response == 0:
    return "alive"
    else:
    return "not alive"
    else:
    response = os.system("ping -c 1 -W 0.5" + host + "> /dev/null")
    if response == 1:
    return "alive"
    else:
    return "not alive"
    

提交回复
热议问题