Article directory
-
- summary
- overall architecture process
- technical process
- summary
Summary
Once you turn off the computer, the campus network will be disconnected for you. I am speechless (he~tui~) for this kind of not-so-smart (extremely s~b) operation. Taking advantage of the fact that I just finished learning reptiles recently, I started automatic login Small program, I’m a rookie, big brother light spray.
Overall Architecture Process
Get request header—>submit data—>package into software—>task scheduler.
Technical process
Now please open your browser and go to the login page (don’t submit, don’t submit, don’t submit), if you submit it, log out and log in again, and open the debugging window (F12, or Fn + F12), it looks different It’s not important, it’s roughly like this, I use Google Chrome, and then go in two steps. For Chinese, the first step is to click “Network”
Then it came to this state. Let’s find the one with the longest green bar in the frame (generally speaking) and click in. If there is no information you want in the next step, it may not be this one. Try one by one.
First find the Request Headers field, please remember this field, and copy it completely, some websites may not have this name, but it doesn’t matter, just look for Headers
Then find the Form Data field, and save it as well. If you can’t find it, just scroll down, and you will always find it.
Find the Request field, this is the URL to be used in the code later, remember it! !
Code
Please look at the code carefully, if there is no library, install it yourself
import subprocess import requests import socket import time # Get local ip def get_host_ip(): try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('10.255.255.255', 1)) ip = s.getsockname()[0] finally: s. close() return ip user_ip = get_host_ip() # Campus network address, it is best not to use the url in the browser, it is recommended to capture the packet post_addr = "This is the URL for you to remember above, fill it in" # The following two curly brackets are copied from the login website of your school’s campus network. Double quotation marks must be added on both sides of the colon, and the fields may be different #But it doesn’t matter, some fields have nothing, but you also need to put double quotes post_header = { 'Accept': 'text/html,application/xhtml + xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v= b3;q=0.9', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'Cache-Control': 'max-age=0', 'Connection': 'keep-alive', 'Content-Length': '391', 'Content-Type': 'application/x-www-form-urlencoded', 'Cookie': 'JSESSIONID-BOSS-2=386C527188F5E01ADA0B6E11C752AFAB; rememberMeCookie=b53fd714e8b5eeddafc11c04225b3da5c9499e45673b2159882231430db45b5b0ac2414 e5db35a60f93603296a85107a; portal_token=b53fd714e8b5eeddc38359f1fc663dc6ac90e96ae9f4227d2dda92239b378c456db5d0aa4895ba28', 'Host': '172.16.253.55', 'Origin': 'http://172.16.253.55', 'Referer': 'http://172.16.253.55/portal.do?wlanacname=000000021.210.00 &wlanuserip=172.20.149.161 &wlanparameter=38.68.93.87.96.dc &usermac= 38:68:93:87:96:dc', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.42', } post_data = { 'hostIp': 'http://127.0.0.1:8082/', 'loginType':'', 'auth_type': '0', 'isBindMac1': '1', 'pageid': '1', 'templatetype': '1', 'listbindmac': '1', 'recordmac': '0', 'isRemind': '1', 'loginTimes':'' , 'groupId': '', 'distoken': '', 'echostr': '', 'url': '', 'isautoauth': '', 'notice_pic_loop1': '/portal/uploads/pc/demo3/images/logo.jpg', 'notice_pic_loop2': '/portal/uploads/pc/demo3/images/rrs_bg.jpg', 'userId': 'My account (manually blocked)', 'passwd': 'My password (funny)', 'twiceauth': '1', 'remInfo': 'on', } # form data in payload #submit data z = requests.post(post_addr, data=post_data, headers=post_header)# submit http request message #PING Baidu to see if there is a successful connection backinfo = subprocess.call('ping www.baidu.com -n 1', shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if backinfo: print('The network is not connected') else: print("Successful login to the campus network, the current IP address is: " + str(user_ip))
This is the code, let’s run it, if nothing unexpected happens, it must be successful
Not much nonsense, just go to the next step, (copy a paragraph)
Pyinstaller is a very useful third-party library for Python. It can package Python source files (ie. py files) into executable files that can be run directly under operating systems such as windows, Linux, and MacOS X. By packaging the source files, the Python program can be run in an environment where Python is not installed, or it can be transferred and managed as an independent file for convenience. Pyinstaller needs to be installed with the pip tool under the command line. The installation is as follows: How to use me, the subject is lazy hahaha
pip install PyInstaller
OK, brothers, by default you have already packed hahaha. Next to the last step, find the task scheduler on your computer. This is win11 for me, and it seems to be the same for win10. I searched it directly and opened it.
Task Scheduler Library — Create Task — Name, check all the checks in my picture.
Then click on the trigger, edit it, and make it into a condition like mine
Click the operation to create a new one, the location of the campus network program you are
After it is finished, it can be seen in the task scheduler library, and this is the end. In the future, every time I open the notebook, it will automatically connect to the campus network, and the annoying pop-up windows will no longer be seen.
Summary
The code can also be optimized. If you need a connected brain at any time when you are away from home, you can also let it execute programs at regular intervals, just change the trigger conditions. ok, don’t forget to like it, brothers.