python 自动重连wifi windows
2016-09-08 19:24
671 查看
# coding=utf-8 import urllib2 import urllib from cookielib import CookieJar import os import re import time class ConnectWeb(object): def __init__(self): self.cookiejarinmemory = CookieJar() self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookiejarinmemory)) urllib2.install_opener(self.opener) self.username = "" self.password = "" def connect_baidu(self): #检测目前是否联网 try: urllib2.urlopen("http://www.baidu.com", timeout=2) return 1 except: return 0 def login(self): #模拟上网验证 验证网页几乎都是不同的,下面附上我们学校的, form表单自己根据情况填,用chrome很容易得到post的url和表单 try: post_url = "" form = {"action": "login", "username": self.username, "password": self.password, "ac_id": 4, "user_ip": "", "nas_ip": "", "user_mac": "", "save_me": 1, "ajax": 1} fm1 = urllib.urlencode(form) page = urllib2.urlopen(post_url, fm1).read() except Exception as e: self.disconnect() time.sleep(1) self.connect_wifi() def disconnect(self): # 断开wifi os.system("netsh wlan disconnect") def wifis_nearby(self): # 查询附近wifi p = os.popen("netsh wlan show all") content = p.read().decode("GB2312", "ignore") temp = re.findall(u"(SSID.*\n.*Network type.*\n.*\u8eab\u4efd\u9a8c\u8bc1.*\n.*\u52a0\u5bc6.*\n.*BSSID.*\n)", content) result = [] for i in temp: name = re.findall(u"SSID.*:(.*)\n", i)[0].replace(" ", "") result.append(name) return result def connect_wifi(self, name=None): #连接wifi os.system("netsh wlan connect name=%s" % name) def checking(self): # 一直检测是否有断网,如果断网则重新连接 while 1: try: if not self.connect_baidu(): self.login() except: pass time.sleep(10) if __name__ == "__main_ 4000 _": test = ConnectWeb() test.login()
相关文章推荐
- Python实现树莓派WiFi断线自动重连的实例代码
- 【转载】Python实现树莓派WiFi断线自动重连
- Windows wifi总是自动断开后重连
- Windows上利用Python自动切换代理IP的终极方案!
- Python实现自动存储Windows 10锁屏聚焦图片到指定文件夹
- windows下python 自动截图功能
- windows下python的自动截图功能
- Windows下自动连接WiFi 脚本
- Python爬虫实战三之实现山东大学无线网络掉线自动重连
- Windows上利用Python自动切换代理IP的终极方案!
- 用python3.x实现北京工业大学的校园网自动登录之bjut_wifi登录
- windows下python安装readline模块 实现自动补全
- 使用Python脚本自动修改Windows的IP、网关和DNS设置
- Windows下Eclipse中Python开发环境的搭建&自动添加utf-8设置
- Python-Windows定时关机与虚拟WIFI
- 卸了免费wifi,诊断后显示Windows无法自动将IP协议堆栈锁定到网络适配器
- Python 自动补齐(CentOS,RedHat,windows)
- (windows)python脚本:自动备份并压缩文件,同时删除过期文件
- Windows下Python自动补全
- Android 如何修改wifi连接失败后自动重连次数?