发布时间:2019-08-30 08:36:26编辑:auto阅读(1547)
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 发送和接收ActiveMQ
下一篇: Ubuntu16.04下完美切换Pyth
47874
46439
37327
34769
29340
26004
24954
19973
19573
18068
5815°
6443°
5955°
5983°
7088°
5932°
5973°
6466°
6430°
7813°