# 自动登录校园网 **Repository Path**: hystudy/loginWeb ## Basic Information - **Project Name**: 自动登录校园网 - **Description**: No description available - **Primary Language**: Python - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 5 - **Forks**: 1 - **Created**: 2021-06-10 - **Last Updated**: 2024-07-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 1.确保连接上了校园网(网线、WiFi都可以) 如果是用WiFi的话要勾选上自动连接: ![image-20210616112258694](https://gitee.com/hystudy/blogimage/raw/master/img/20210616123251.png) # 2.下面开始分析网页: 打开你的浏览器 在浏览器中输入:172.17.1.2 (*这是我学校的校园网登录页面,你需要输入你自己学校的校园网登录页面*) ![image-20210616112436643](https://gitee.com/hystudy/blogimage/raw/master/img/20210616112516.png) 填入你自己的账号和密码,然后按下F12: ![image-20210616120013962](https://gitee.com/hystudy/blogimage/raw/master/img/20210616120202.png) 点击了登录后: ![image-20210616112540634](https://gitee.com/hystudy/blogimage/raw/master/img/20210616112542.png) 点开后: ![image-20210616120116946](https://gitee.com/hystudy/blogimage/raw/master/img/20210616120125.png) 移下去有个请求参数(记住): ![image-20210616113113010](https://gitee.com/hystudy/blogimage/raw/master/img/20210616120129.png) 我们点击clear按钮: ![image-20210616112641735](https://gitee.com/hystudy/blogimage/raw/master/img/20210616120215.png) 然后再刷新一下: 请求头: ![image-20210616112832111](https://gitee.com/hystudy/blogimage/raw/master/img/20210616120218.png) url: ![image-20210616112928855](https://gitee.com/hystudy/blogimage/raw/master/img/20210616120221.png) 以上就是网页的分析,下面我们要开始写代码了。 --------------------------------------------------------------------------------------- # 3.编写Pycharm代码 **直接开始写代码:** **注意:我们需要导入requests这个库,如果你没下载,可以先去下载好** **在cmd中键入:**pip3 install requests 然后回车即可 在本文下面安装pyinstaller这个库的时候有较为详细的教程 ***照着我注释的说明改就行了\*** ![image-20210616113308977](https://gitee.com/hystudy/blogimage/raw/master/img/20210616120224.png) ```python import requests url = 'http://172.17.1.2/' # 这行是你需要根据自己的情况修改的地方 data = { "DDDDD": '', # 这行是你需要根据自己的情况修改的地方 "upass": '', # 这行是你需要根据自己的情况修改的地方 # 下面的这些一般可以直接用(不用改),也有可能要根据你自己的浏览器中的data(数据)做些修改 "R1": "0", "R3": "1", "R6": "0", "pare": "00", "OMKKey": "123456", } # 这整个header都是需要根据网页中的请求头来做修改 # 下面这个header是我的,你需要按照你自己浏览器中出现的Request Headers(请求标头)来修改。 header = { "Accept": "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8", "Connection": "keep-alive", "Host": "172.17.1.2", "Referer": "http://172.17.1.2/a79.htm?isReback=1", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36", "X-Requested-With": "XMLHttpRequest", } response = requests.post(url, data, headers=header).status_code # 获取状态码 print("回应代码{}".format(response)) # 打印状态码 if response == 200: print("登录成功,按下任回车键退出!") else: print("登录失败,请手动登录!") print("需要移除黑色命令窗口请联系管理员!QQ:2389407153") input() ``` 写完后,断开你的校园网(点击注销就行): ![image-20210616120300603](https://gitee.com/hystudy/blogimage/raw/master/img/20210616120306.png) 然后运行你的Python代码: 可以看到返回的状态码是200 ![image-20210616120326567](https://gitee.com/hystudy/blogimage/raw/master/img/20210616122555.png) 然后在浏览器页面中刷新一下校园网:登陆成功 ![image-20210616120356426](https://gitee.com/hystudy/blogimage/raw/master/img/20210616120358.png) 这样我们就通过运行Python代码登录校园网了 --------------------------------------------------------------------------------- # 4.下面将介绍如何把我们刚刚写好的Python代码打包成.exe文件 首先你需要安装pyinstaller这个库 ## 1.可以在cmd下使用命令安装: 按WIN+R,然后在窗口中输入cmd,再回车。 然后在其中键入命令:pip3 install pyinstaller 然后回车 ![image-20210616120614649](https://gitee.com/hystudy/blogimage/raw/master/img/20210616120619.png) ## 2.你也可以在Pycharm里安装pyinstaller ![image-20210616120645752](https://gitee.com/hystudy/blogimage/raw/master/img/20210616120646.png) ![image-20210616120808828](https://gitee.com/hystudy/blogimage/raw/master/img/20210616122514.png) ![image-20210616120847218](https://gitee.com/hystudy/blogimage/raw/master/img/20210616122512.png) 等待安装即可。 *以上1和2两种方法都能安装,看你自己喜欢用哪种~* ## 3.下面开始利用pyinstaller来打包 1.在cmd下进入.py文件的目录下(我们刚刚写好的代码存放的目录) 如何进入? 找到你刚刚写的代码所在的位置: ![image-20210616120944586](https://gitee.com/hystudy/blogimage/raw/master/img/20210616122509.png) 地址栏输入cmd,回车 在cmd直接输入:pyinstaller - F _init_.py 上面这行命令中的"_init_.py"是我写的Python代码的名称,你需要填写你自己Python代码的名称。 ![image-20210616121100355](https://gitee.com/hystudy/blogimage/raw/master/img/20210616122507.png) 等待它打包即可。 完成后会像我这样多出一些文件: ![image-20210616121153792](https://gitee.com/hystudy/blogimage/raw/master/img/20210616122504.png) ![image-20210616121201041](https://gitee.com/hystudy/blogimage/raw/master/img/20210616122502.png) 右键创建快捷方式,粘贴到桌面 你可以把它拖出来放在和.py同级的目录下 然后你可以运行看看效果怎么样 这样我们就把我们写的代码打包好了。 下面开始介绍如何在电脑开机时就运行这个.exe程序 桌面win+R打开运行窗口 输入 shell:startup ![image-20210616122339199](https://gitee.com/hystudy/blogimage/raw/master/img/20210616122459.png) 进入文件夹:把刚刚打包好的程序放进去 ![image-20210616122303175](https://gitee.com/hystudy/blogimage/raw/master/img/20210616122457.png) 最后重启试验 一定要在wifi那勾选自动连接https://gitee.com/gitee-stars/)