网络编程
位置:首页>> 网络编程>> Python编程>> python监测当前联网状态并连接的实例

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

作者:jinjie412  发布时间:2023-04-19 03:33:19 

标签: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()

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

来源:https://blog.csdn.net/jinjie412/article/details/51484103

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com