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 ...
随机推荐
- Extjs 组件继承 模板说明(同GridPanel案件)
1. 重写initComponent()方法,并在该方法在调用父类的initComponent()方法. 如:subclass.superclass.initComponent.call(this) ...
- Apache2.4.x与Apache2.2.x的一些区别
改用Apache2.4一段时间了,一直没发现它和Apache2.2的有什么区别,一些基本配置都是差不多,直到前几天配置虚拟主机是才发现了一些小小的不同 一直以来我都是在htdocs目录下配置虚拟主机的 ...
- c语言可变参函数探究
一.什么是可变长参数 可变长参数:顾名思义,就是函数的参数长度(数量)是可变的.比如 C 语言的 printf 系列的(格式化输入输出等)函数,都是参数可变的.下面是 printf 函数的声明: in ...
- Python语言在企业级应用上的十大谬误
英文原文:https://www.paypal-engineering.com/2014/12/10/10-myths-of-enterprise-python/ 翻译原文:http://www.os ...
- Data Annotations
Data Annotations Entity Framework Code First 利用一种被称为约定(Conventions)优于配置(Configuration)的编程模式允许你使用自己 ...
- Asp.Net Web API 导航3
Asp.Net Web API 导航 Asp.Net Web API第一课:入门http://www.cnblogs.com/aehyok/p/3432158.html Asp.Net Web A ...
- UVA 10392 (13.07.28)
Problem F: Factoring Large Numbers One of the central ideas behind much cryptography is that factori ...
- 细节MARK
在刷vijos1046的时候遇到了一些细节,MARK一下 1.哲学之前有告诫我说,输出long long的数的时候,最好用cout,不然容易出现编译器的问题,今天算是领教了 2.对于数组赋值问题 me ...
- 事件聚合IEventAggregator和 Ihandle<T>
-事件聚合IEventAggregator和 Ihandle<T> 今天 说一下Caliburn.Micro的IEventAggregator和IHandle<T>分成两篇 ...
- apache Alias使用问题
今天在配置apache的过程中,使用了Alias,但是由于配置错误导致403 forbidden错误,不能正常访问. 首先理解一下Alias,Alias就是别名的意思,假如我的项目目录在/home/w ...