Python wifi掉线重连接
原理很简单,通过python执行dos命令 : ping 和 netsh
需要用到os和time模块
代码如下:
>>> import os
>>> print 'wifi掉线'
wifi掉线
>>> import time
>>> while True:
... status = os.system("ping -c 1 www.baidu.com")
... if status == 1:
... print 'wifi掉线'
... os.system('netsh wlan connect name=DSGY2')
... else:
... print '连接状态'
... time.sleep(180)
大家使用时将name=XX ,名字改一下,在我的机子上测试通过,该脚本3分钟检测一次是否掉线
如果你的wifi在手动连接都连不上,那这段脚本就没用了
------------------------------------------------------------------------------------------------------------------------
Pinging www.a.shifen.com [14.215.177.37] with 32 bytes of data:
Reply from 14.215.177.37: bytes=32 time=24ms TTL=54
Reply from 14.215.177.37: bytes=32 time=63ms TTL=54
Reply from 14.215.177.37: bytes=32 time=32ms TTL=54
Reply from 14.215.177.37: bytes=32 time=26ms TTL=54
Ping statistics for 14.215.177.37:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 24ms, Maximum = 63ms, Average = 36ms
连接状态
Pinging www.a.shifen.com [180.97.33.108] with 32 bytes of data:
Reply from 180.97.33.108: bytes=32 time=1676ms TTL=54
Reply from 180.97.33.108: bytes=32 time=544ms TTL=54
Reply from 180.97.33.108: bytes=32 time=2033ms TTL=54
Reply from 180.97.33.108: bytes=32 time=291ms TTL=54
Ping statistics for 180.97.33.108:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 291ms, Maximum = 2033ms, Average = 1136ms
连接状态
Pinging www.a.shifen.com [180.97.33.107] with 32 bytes of data:
Reply from 180.97.33.107: bytes=32 time=126ms TTL=54
Reply from 180.97.33.107: bytes=32 time=294ms TTL=54
Reply from 180.97.33.107: bytes=32 time=57ms TTL=54
Reply from 180.97.33.107: bytes=32 time=131ms TTL=54
Ping statistics for 180.97.33.107:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 57ms, Maximum = 294ms, Average = 152ms
连接状态
----------------------------------------------------------------------------------------------------------------
昨天没有把代码保存,也没有碰到掉线的情况
#-*-coding:utf-8-*-
import os
import time
while True:
status = os.system('ping -c 1 www.baidu.com')
if status == 1:
print u'wifi掉线'
os.system('netsh wlan connect name=haha')
else:
print u'连接状态'
time.sleep(30)
运行情况
Pinging www.a.shifen.com [180.97.33.108] with 32 bytes of data:
Reply from 180.97.33.108: bytes=32 time=21ms TTL=56
Reply from 180.97.33.108: bytes=32 time=22ms TTL=56
Reply from 180.97.33.108: bytes=32 time=45ms TTL=56
Reply from 180.97.33.108: bytes=32 time=25ms TTL=56
Ping statistics for 180.97.33.108:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 21ms, Maximum = 45ms, Average = 28ms
连接状态
Ping request could not find host www.baidu.com. Please check the name and try again.
wifi掉线
Connection request was completed successfully.
Pinging www.a.shifen.com [180.97.33.108] with 32 bytes of data:
Reply from 180.97.33.108: bytes=32 time=26ms TTL=56
Reply from 180.97.33.108: bytes=32 time=27ms TTL=56
Reply from 180.97.33.108: bytes=32 time=27ms TTL=56
Reply from 180.97.33.108: bytes=32 time=28ms TTL=56
Ping statistics for 180.97.33.108:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 26ms, Maximum = 28ms, Average = 27ms
连接状态
---注意:在管理员权限下运行脚本
Python wifi掉线重连接的更多相关文章
- WCF心跳判断服务端及客户端是否掉线并实现重连接
WCF心跳判断服务端及客户端是否掉线并实现重连接 本篇文章将通过一个实例实现对WCF中针对服务端以及客户端是否掉线进行判断:若掉线时服务器或客户端又在线时将实现自动重连:将通过WCF的双工知识以及相应 ...
- wind10系统 Atheros AR9271 Wireless Network Adapter USBwifi无线网卡的驱动安装解决无法搜索wifi信号,连接wifi信号无法上网的问题
一.解决无法搜索wifi信号的问题 卸载掉之前的驱动,上网下载其他的驱动程序安装. http://drivers.mydrivers.com/drivers/463_185289.htm 二.安装完后 ...
- python之requests urllib3 连接池
0.目录 1.参考 2. pool_connections 默认值为10,一个站点主机host对应一个pool (4)分析 host A>>host B>>host A pag ...
- [Spark][Python]DataFrame的左右连接例子
[Spark][Python]DataFrame的左右连接例子 $ hdfs dfs -cat people.json {"name":"Alice",&quo ...
- Atitit 列出wifi热点以及连接
Atitit 列出wifi热点以及连接 配置命令 >netsh wlan /?1 显示已经有的配置netsh wlan show profiles1 C:\Users\Administrato ...
- python中实现mysql连接池
python中实现mysql连接池 import pymysql from DBUtils.PooledDB import PooledDB MYSQL_HOST = 'localhost' USER ...
- Python和mysql的连接
python与mysql的连接: 说明:前提是已近安装了mysql以及可视化工具(本人装的是Navicat) 1.在cmd下下载Python的第三方数据库包:pip install pymysql: ...
- python中列表元素连接方法join用法实例
python中列表元素连接方法join用法实例 这篇文章主要介绍了python中列表元素连接方法join用法,实例分析了Python中join方法的使用技巧,非常具有实用价值,分享给大家供大家参考. ...
- ws & websocket & 掉线重连
ws & websocket & 掉线重连 reconnecting websocket https://github.com/joewalnes/reconnecting-webso ...
随机推荐
- OpenWrt的UCI系统
http://wiki.openwrt.org/doc/uci UCI是Unified Configuration Interface的缩写,翻译成中文就是统一配置接口,用途就是为OpenWrt提供一 ...
- 解决水晶报表提示“未知的查询引擎错误” FOR VS2010
原文:解决水晶报表提示“未知的查询引擎错误” FOR VS2010 在VS2010环境下运行水晶报表(当然要先装上Crystal Report For VS2010), 在SetDataSource方 ...
- vs 文件头自动添加注释
原文:vs 文件头自动添加注释 vs2010 C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates ...
- 18. Scrum敏捷软件开发
1)柯维定律 2)如何组件敏捷团队? 团队5~9个人,Mike带过最多的是14个人.个人建议,别超过10个.否则沟通的成本直线上升.(团队的午餐,两个匹萨就够了). 引入特性团队(针对于传统的组件 ...
- Effective C++(12) 复制对象时要复制每一个成员
问题聚焦: 负责拷贝的两个操作:拷贝构造函数和重载赋值操作符. 一句话总结,确保被拷贝对象的所有成员变量都做一份拷贝. Demo void logCall(const std::string&am ...
- c#中关于sealed修饰类的性能提升的测试
在clr var c#一书中,作者描述当用sealed修饰类时,可以提高系统性能而且建议大家也养成用sealed来修饰类的习惯.由于对性能二字比较敏感,所以本文先测试一下用sealed分别修饰和不修饰 ...
- Identity
ThreadStatic应用(Identity补完) 关于Identity Identity自增序列/唯一断标识 起初做这个东西,是在一个内部组件中,用于在高并发的环境下得到一个较短的“相对”不重 ...
- noip模拟赛:部队[技巧?思想?]
王国军总指挥——卡西乌斯准将决定重建情报局,需要从全国各地挑选有能力的士兵,选择的标准为A,B两种能力.对于每个候选士兵,如果存在另一名士兵的两项能力均大于等于他,那么他将被淘汰.(注意:若两名士兵两 ...
- 用py2exe打包pyqt4出现的问题(转)
使用pyqt完成窗体界面很方便,但是打包成exe之后会有问题,在网上找到解决办法如下: Another Solution to the same problem: from distutils.cor ...
- python 开发利器
UliPad 初体验----python 开发利器 Posted on 2013-10-28 22:36 虫师 阅读(436) 评论(3) 编辑 收藏 学习python 有段时间,最近博客更新比较慢了 ...