【发布时间】:2021-07-09 12:18:12
【问题描述】:
import os
hostnames = [
"facebook.com",
"google.ge",
"test.com"
]
while True:
for hostname in hostnames:
response = os.system('ping -c 1 ' + hostname)
if response == 0:
print('ping {}'.format(hostname))
else:
print('not ping')
您好,这是我的代码,我的目标是检查几个站点 ping,但是如果站点不 ping 我想 ping 这个站点直到站点可用并且需要 print('site is available') 但是当一个站点已关闭此脚本必须继续检查其他站点
警报希望是这样的,例如:
facebook.com - ping good
test.com - not ping
test.com - Resurrected and ping good
....
【问题讨论】:
标签: python python-3.x python-requests