import time
def check_ping():
hostname = "XXX.com"
response = os.system("ping -c 1 " + hostname)
# and then check the response...
if response == 0:
pingstatus = "Network Active"
else:
pingstatus = "Network Error"
return pingstatus
while 1:
print(check_ping())
time.sleep(3600)
擷取自:https://stackoverflow.com/questions/26468640/python-function-to-test-ping
google關鍵字: python ping test