python判断计算机是否有网络连接的实例_python_脚本之家


 



def isConnected():
import requests
try:
html = requests.get("http://www.baidu.com",timeout=2)
print("网络正常")
return 1
except:
print("网络异常")
return 0

Flag = isConnected()
print(Flag)