下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
#!/usr/bin/env python# Coding: utf-8__author__ = 'Elva'import osimport timeimport sys#import datetimefrom time import localtime,strftime###每N分钟检查一次网络,如果断开进行重连#f_handler=open('net_check.log','w')#sys.stdout=f_handler#ISOFORMAT='%Y-%m-%d %H:%M:%s' #设置输出格式# isinstance(c,int)# CAO_NI_MA3 = ''' ┏┓ ┏┓ ┏┛┻━━━┻┗┓ ┃ ┃ ┃ ━ ┃ ┃ ┳┛ ┗┳ ┃ ┃ ┃ ┃ ┻ ┃ ┗━┓ 神 ┏━┛ ┃ 兽 ┃ ┏━━━┛ 佑 ┃ ┏┛ 护 ┃ ┗┓ ┃ ┗┓┏┳━┓┏┏┛ ┣┣┃ ┣┣┃ ┗┻┛ ┗┻┛ ''' CAO_NI_MA = ''' ┏┓ ┏┓ ┏┛┻━━━┻┗┓ ┃ ┃ ┃ ━ ┃ ┃ ┳┛ ┗┳ ┃ ┃ ┃ ┃ ┻ ┃ ┗━┓ ┏━┛ ┃ 草 ┃ ┏━━━┛ 尼 ┃ ┏┛ 玛 ┃ ┗┓ ┃ ┗┓┏┳━┓┏┏┛ ┣┣┃ ┣┣┃ ┗┻┛ ┗┻┛ ''' def incCount(): '''计数+1''' fh = open("rc_count.txt",'r+') count_ = fh.read() count_ = int(count_) count_ = count_ + 1 #print count_ fh.seek(0) fh.write(str(count_)) fh.close()def log(text): ''' 记录日志''' #global ISOFORMAT #Now = datetime.datetime.Now() NowStr = strftime("%Y-%m-%d %H:%M:%s",localtime()); msg = NowStr + " : " + text print(msg) fh = open("_netcheck.log",'a') fh.write(msg + "\n") fh.close()log("********************【--GOOD_LUCK--】********************")log(CAO_NI_MA3)log("********************【--GOOD_LUCK--】********************")#log("qcc") #等待多少秒def wait(s): ''' 等待S秒''' #print("---------------------SLEEP(%ss)--------------------" %s) if s <= 0: return i = s*2-1; while i > 0: i=i-1 time.sleep(0.5) print '.',time.sleep(0.5) print '.' #print("---------------------SLEEP(%ss)-------------------" %s)#wait(3)#检查网络计数check_net_count = 0#重连计数reconnect_count = 0#域名索引domain_index = 0def check_net(): '''检查网络''' print(""); global check_net_count global reconnect_count global domain_index check_net_count=check_net_count+1 log("---------------------CHECK_NET_STA(%d)---------------------" %check_net_count) #Ping_@R_301_6818@ =["www.qq.com","www.163.com","www.sohu.com","www.sina.com","www.oschina.net","www.hao123.com","www.taobao.com","www.autohome.com.cn","www.youku.com","www.jd.com","www.iteye.com","www.ctrip.com"] Ping_@R_301_6818@ = ["www.baIDu.com","www.weibo.com","www.qq.com","www.1688.com","mail.126.com","www.ctrip.com","www.360.cn","www.iciba.com","www.wiz.cn","www.csdn.net","www.net.cn","mail.163.com","www.weiyun.com","www.suning.com","www.ganji.com","www.xcar.com.cn","mail.qq.com","www.ifeng.com","www.yhd.com","www.lIEpin.com","www.xunlei.com","www.weibo.cn","www.xxsy.net","www.dianPing.com","www.mop.com","www.126.com","www.zol.com.cn","www.qunar.com","www.alipay.com","www.17173.com","www.4399.com","www.fang.com","www.baihe.com","www.51job.com","www.letv.com","www.iqiyi.com","www.58.com","www.amazon.cn","www.gome.com.cn"] #Ping_@R_301_6818@ =["www.baIDu.com","www.oschina.net"] Ping_str = "Ping -n 1 " + Ping_@R_301_6818@[(domain_index)%(len(Ping_@R_301_6818@))] log("INFO:Ping:["+ Ping_@R_301_6818@[(domain_index)%(len(Ping_@R_301_6818@))] +"]...") domain_index = domain_index + 1; #ret = os.system("Ping www.qq.com") ret = os.system(Ping_str) log("INFO:Ping STATUS_CODE:%d" %ret) if ret: #try again log("WARN:NET MAY DOWN,try2 next domain!!!") #time.sleep(5)#暂停N秒 wait(3) Ping_str = "Ping " + Ping_@R_301_6818@[(domain_index)%(len(Ping_@R_301_6818@))] log("INFO:Ping2:["+ Ping_@R_301_6818@[(domain_index)%(len(Ping_@R_301_6818@))] +"]...") domain_index = domain_index + 1; # domain_index+=1 ret = os.system(Ping_str) log("INFO:Ping2 STATUS_CODE:%d" %ret) if ret: #try again log("WARN:NET MAY DOWN,try3 next domain!!!") #time.sleep(5)#暂停N秒 wait(3) Ping_str = "Ping " + Ping_@R_301_6818@[(domain_index)%(len(Ping_@R_301_6818@))] log("INFO:Ping3:["+ Ping_@R_301_6818@[(domain_index)%(len(Ping_@R_301_6818@))] +"]...") domain_index = domain_index + 1; # domain_index+=1 ret = os.system(Ping_str) log("INFO:Ping3 STATUS_CODE:%d" %ret) if not ret: log("INFO:NET IS OK (RC=%d)!!" %reconnect_count) log("---------------------CHECK_NET_END(%d)---------------------\n" %check_net_count) else: print(CAO_NI_MA) log("FUCK:NET IS DOWN!") reconnect_count = reconnect_count + 1 incCount() log("INFO:尝试断开重连(%d)..." %reconnect_count); #先断开连接 log("INFO:尝试断开连接..."); netsh_ret = os.system("netsh wlan disconnect") wait(3) log("INFO:尝试重新连接..."); netsh_ret = os.system("netsh wlan connect name=TP-link_490A") #wait(2) log("INFO:NETSH_RET STATUS_CODE:%d" %netsh_ret) log("---------------------CHECK_NET_END(%d)---------------------\n" %check_net_count)#incCount()while True: check_net() time.sleep(45)#每五分钟Ping一次 #time.sleep(10)#每五分钟Ping一次
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的wifi 掉线自动重连全部内容,希望文章能够帮你解决wifi 掉线自动重连所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)