python监测当前联网状态并连接的实例

yipeiwu_com6年前Python基础

如下所示:

def test1():
 import os
 return1=os.system('ping 8.8.8.8')
 if return1:
  print 'ping fail'
  os.system('msdt.exe /id NetworkDiagnosticsNetworkAdapter')#调用系统网络诊断
 else:
  print 'ping'
def test2():
 import os
 import subprocess
 
 fnull = open(os.devnull, 'w')
 return1 = subprocess.call('ping 8.8.8.8', shell = True, stdout = fnull, stderr = fnull)
 if return1:
  return1 = subprocess.call('msdt.exe /id NetworkDiagnosticsNetworkAdapter', shell=True, stdout=fnull, stderr=fnull)
  print 'ping fail'
 else:
  print 'ping ok'
 fnull.close()
 
if __name__=='__main__':
 test2()

监测当前是否联网,没有时调用系统的联网监测;也算是原创吧,百度了下,功能都是分开的,综合到了一起。

以上这篇python监测当前联网状态并连接的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python中int()函数的用法浅析

int()是Python的一个内部函数  Python系统帮助里面是这么说的 >>> help(int) Help on class int in...

Python解决线性代数问题之矩阵的初等变换方法

定义一个矩阵初等行变换的类 class rowTransformation(): array = ([[],[]]) def __init__(self,array):...

使用Python3 编写简单信用卡管理程序

1、程序执行代码: #Author by Andy #_*_ coding:utf-8 _*_ import os,sys,time Base_dir=os.path.dirname...

python简单的函数定义和用法实例

本文实例讲述了python简单的函数定义和用法。分享给大家供大家参考。具体分析如下: 这里定义了一个温度转换的函数及其用法。 def convertTemp(temp, scale)...

基于python3 OpenCV3实现静态图片人脸识别

基于python3 OpenCV3实现静态图片人脸识别

本文采用OpenCV3和Python3 来实现静态图片的人脸识别,采用的是Haar文件级联。 首先需要将OpenCV3源代码中找到data文件夹下面的haarcascades文件夹里...