前言
最近买了笔记本,每次登录学校wifi都会弹出portal让我登录,非常麻烦,于是想写个python自动登录
抓包分析
打开charles——我最爱的抓包软件,点击登录,可以找到这个登录button向172.30.21.100的接口发送了post请求
仔细分析一下数据
好像没什么要分析的
是一个post请求加上form表单
分析到此直接写代码就行了
python代码实现
import requests import time # 一个自动登录WLAN程序 class AutoLoginWLAN: def testConnection(self): res = requests.get("https://ipw.cn") if res.status_code != 200: # self.login() return False else: return True def login(self): headers = { "Host":"172.30.21.100", "Origin":"http://172.30.21.100", "Referer":"http://172.30.21.100/tpl/whut/login.html?nasId=14", "Content-Type":"application/x-www-form-urlencoded" } data = { "username":"xxxxxx", "password":"xxxxxx", "nasId":14 } res = requests.post("http://172.30.21.100/api/account/login",data=data) if __name__ == "__main__": loginProcess = AutoLoginWLAN() while True: if loginProcess.testConnection(): loginProcess.login() time.sleep(5) # 五秒重复一次登录 else: time.sleep(300) # 5分钟检查一次是否登录
|
打包成exe
使用pyinstaller打包
命令行
pyinstaller autologinwlan.py -F -w
|
-F打包成单个文件,-w关闭命令行输出选项
放到启动里自动启动
多余的解释
后记
懒人是这样的
github项目地址自动登录wifi