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实现网站微信登录的示例代码

最近微信登录开放公测,为了方便微信用户使用,我们的产品也决定加上微信登录功能,然后就有了这篇笔记。 根据需求选择相应的登录方式 python实现网站微信登录的示例代码 微信现在提供两种...

对python中的xlsxwriter库简单分析

一、xlsxwriter 基本用法,创建 xlsx 文件并添加数据 官方文档:http://xlsxwriter.readthedocs.org/ xlsxwriter 可以操作 xls...

python 多个参数不为空校验方法

在实际开发中经常需要对前端传递的多个参数进行不为空校验,可以使用python提供的all()函数 if not all([arg1, arg2, arg3]): # 当 arg1,...

pytorch下大型数据集(大型图片)的导入方式

使用torch.utils.data.Dataset类 处理图片数据时, 1. 我们需要定义三个基本的函数,以下是基本流程 class our_datasets(Data.Datas...

Python编程实现微信企业号文本消息推送功能示例

本文实例讲述了Python微信企业号文本消息推送功能。分享给大家供大家参考,具体如下: 企业号的创建、企业号应用的创建、组、tag、part就不赘述了,一搜一大堆,但是网上拿的那些个脚本...