import os import time import winsound iplist = list() ip = 'www.baidu.com' while(1): backinfo = os.system('ping -n 1 %s'%ip) # 实现pingIP地址的功能,-c1指发送报文一次,-w1指等待1秒 time.sleep(1) if backinfo: print('网络不通') else: duration = 1500 # millisecond freq = 440 # Hz winsound.Beep(freq, duration) print ('backinfo',backinfo)