欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python測試網(wǎng)絡連通性示例【基于ping】

 更新時間:2018年08月03日 10:19:14   作者:Teingi  
這篇文章主要介紹了Python測試網(wǎng)絡連通性,結合實例形式分析了Python通過發(fā)送ping請求測試網(wǎng)絡連通性相關操作技巧,需要的朋友可以參考下

本文實例講述了Python測試網(wǎng)絡連通性。分享給大家供大家參考,具體如下:

Python代碼

#!/usr/bin/python
# -*- coding:GBK -*-
"""Document: network script, keep network always working, using python3"""
import os
import time
PING_RESULT = 0
NETWORK_RESULT = 0
def DisableNetwork():
 ''' disable network card '''
 result = os.system(u"netsh interface set interface 以太網(wǎng) disable")
 if result == 1:
  print("disable network card failed")
 else:
  print("disable network card successfully")
def ping():
 ''' ping 主備網(wǎng)絡 '''
 result = os.system(u"ping 180.97.33.108")
 #result = os.system(u"ping www.baidu.com -n 3")
 if result == 0:
  print("A網(wǎng)正常")
 else:
  print("網(wǎng)絡故障")
 return result
if __name__ == '__main__':
 while True:
  PING_RESULT = ping()
  if PING_RESULT == 0:
   time.sleep(20)
  else:
   DisableNetwork()
   time.sleep(10)

運行結果:

注:原文為utf-8編碼,這里小編測試時發(fā)現(xiàn)返回結果會出現(xiàn)亂碼,故改為GBK編碼。

更多關于Python相關內(nèi)容可查看本站專題:《Python Socket編程技巧總結》、《Python數(shù)據(jù)結構與算法教程》、《Python函數(shù)使用技巧總結》、《Python字符串操作技巧匯總》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總

希望本文所述對大家Python程序設計有所幫助。

相關文章

最新評論