介绍
这篇文章给大家介绍使用Python怎么测试网络的连通性,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
Python代码
# !/usr/bin/Python #,- *安康;编码:GBK - * “““文档:,network 脚本,,keep network always 工作,,using python3"““ import 操作系统 import 时间 PING_RESULT =0 NETWORK_RESULT =0 def DisableNetwork (): ,& # 39;& # 39;& # 39;,disable network card & # 39; & # 39; & # 39;=,,result  os.system (u" netsh  interface set interface 以太网,disable") ,if result ==, 1: 打印才能(“disable  network card failed") ,其他的: 打印才能(“disable  network card successfully") def ping (): ,& # 39;& # 39;& # 39;,ping 主备网络,& # 39;& # 39;& # 39;=,,result  os.system (u" ping 180.97.33.108") ,# result =, os.system (u" ping www.baidu.com -n 3,) ,if result ==, 0: 打印才能(“网正常“) ,其他的: 打印才能(“网络故障“) return 结果 if __name__ ==, & # 39; __main__ # 39;: ,while 真正的: PING_RESULT =,才能ping () if 才能;PING_RESULT ==, 0: ,,time . sleep (20) 其他的才能: ,,DisableNetwork () ,,time . sleep (10)
运行结果: