One of the more troublesome aspects of Digital Zhongnan is that you need to log in every day to turn on the computer.
Or every time around midnight, the internet will be disconnected suddenly
This is how uncomfortable it is for one of my lol players to suddenly disconnect
In addition, I want to get started with the Raspberry Pi recently, but I need to open a browser to verify the Internet connection.
Just write it directly into a python script
Ado
The first step is definitely to start with packet capture
First open the campus network login interface
The packet capture tool I use here is Fiddler4, of course, you can also use other software
Then I log in to the campus network once, and the following is the result of the packet capture
Then Fiddler4 save (File -> Save -> All sessions)
Save it and watch it slowly, after all, I am also cute
Then we can see that it is easy to see a request whose URL is /portaNat444/AccessServices/login.
Let's click in to see the content of request and response
We found that the accountID in the post request is the account number +%40zndx.inter in the input box, and the password is the encrypted password
brasAddress is the address of the access point device
userIntranerAddress is the network address
Then it’s time to write the script. The network address may be different every time you log in, and the access point device remains unchanged.
So we have to write a method to get it, it's actually very simple, just two lines
def get_ip(): host_name = socket.gethostname() return socket.gethostbyname(host_name)
Then, we copy the request header, which is the third picture of this article
post_header = { 'Host': '61.137.86.87:8080', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko Core/1.63.6756.400 QQBrowser/10.2.2518.400', 'Accept': 'application/json, text/javascript, */*; q=0.01', 'Accept-Language': 'zh-CN', 'Accept-Encoding': 'gzip, deflate', 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8', 'X-Requested-With': 'XMLHttpRequest', 'Referer': 'http://61.137.86.87:8080/portalNat444/index.jsp', 'Content-Length': '355', 'Cookie': 'JSESSIONID=2F975DCF3FBC710D56CEA180C4EF8F65', 'Connection': 'keep-alive', }
Forget it, put the code directly
#coding=utf-8 import them import socket from subprocess import check_output import urllib.request def login(): print("------loading------") post_header = { 'Host': '61.137.86.87:8080', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko Core/1.63.6756.400 QQBrowser/10.2.2518.400', 'Accept': 'application/json, text/javascript, */*; q=0.01', 'Accept-Language': 'zh-CN', 'Accept-Encoding': 'gzip, deflate', 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8', 'X-Requested-With': 'XMLHttpRequest', 'Referer': 'http://61.137.86.87:8080/portalNat444/index.jsp', 'Content-Length': '355', 'Cookie': 'JSESSIONID=2F975DCF3FBC710D56CEA180C4EF8F65', 'Connection': 'keep-alive', } account = "[email protected]" account1 = "[email protected]" password1 = "55893d79972c1b2b1b31496c5cd0baf6083d321072c5c8f9b73335a359164aa5174acc9d3224bc93619d793b17d8ae5085f9370beb171744f13a62f5f545d3d7c44bf25aee4c4807e8e7dfa5eae1388a5205b3b3ac8a091e9501b42feb532cc4c1c9cceafda36d96533888055de3a4bea1c1c63523daec3e2cb1959b7a5ad86b" password = "8312df7aa6c9daae13110210f4df47450858540b654094ff8ae56d1b38aeb182be1e34b7b9b33d5f11fdb6f195c46bc2e227008534cc5980ed12bc1e36a8068034c51b218b3c6c0db83ea03c0d3140ea8d83f2b8ce2706eea68fb430bb86c012c55690cab0f0a5aba5216902640992ab456feee00b84654d690088643dec8949" brasAddress = "59df7586" ip = get_ip() print(ip) url = "http://61.137.86.87:8080/portalNat444/AccessServices/login" formData = {'accountID': account, 'password': password, 'brasAddress': brasAddress, 'userIntranetAddress': ip} # Convert str type to bytes type data = urllib.parse.urlencode(formData).encode("utf-8") request = urllib.request.Request(url, data=data,headers=post_header) print(urllib.request.urlopen(request).read().decode("utf-8")) # The second method of obtaining an IP address def get_ip(): host_name = socket.gethostname() return socket.gethostbyname(host_name)
if __name__ == '__main__': login()