亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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

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)絡(luò) '''
 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)絡(luò)故障")
 return result
if __name__ == '__main__':
 while True:
  PING_RESULT = ping()
  if PING_RESULT == 0:
   time.sleep(20)
  else:
   DisableNetwork()
   time.sleep(10)

運行結(jié)果:

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

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

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

相關(guān)文章

最新評論