【发布时间】:2016-07-04 19:14:35
【问题描述】:
我正在使用:Windows 我正在尝试在 ping ip 地址时创建一个简单的if 语句
import os
hostname = "192.168.8.8." #example
response = os.system("ping -c 1 " + hostname)
#and then check the response...
if response == 0:
print hostname, 'is down'
else:
print hostname, 'is up'
print response
我对此很陌生,但无论我输入的 ip 地址是什么,有效与否,它都会显示它已启动。
【问题讨论】: