Python implementation – campus network automatic login

Writing in the front

Campus network is now one person one system, each link to the campus network will have to open the browser to enter the account password to log in, a little trouble, in order to save time, research, decided to use Python to write an automatic login script, this article content is only for reference, what is not enough to leave a message in the comment area yo ~~

tool

– Chrome (installation package download: [download] baidu network backup pan.baidu.com/s/1oOduV5ZF… Pih7) -Pycharm -Python +requests package

Browser operations

** Open a browser :** Enter the campus network login address: 192.168.3.5 (the login address varies from school to school)

Use check mode to check web pages

F12 open the check mode, the first step will check Network– enter the account password on the login interface — click login — a.php file will be requested below, and this is the file we need to operate

Open up the PHP file and check the file Request header-request URL which is the URL that we logged in to -From Data which is the Data in the Request package

Python main code

# login function
def login_request(name, password):
    Print a prompt when the network is not connected
    # print("[03] {} raspberry is offline, request now... ".format(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
    #password = base64.b64encode(password.encode())
    Package request data
    data1 = {"action": "login"."username": name,
             "password": password,
             "ac_id": 1,
             "save_me": 1,
             "ajax": 1}
    try:
        result = requests.post(LOGIN_PAGE_URL, data=data1)
        Print the request result
        print(result.text)
        # Displays a successful login message
        print("[01] {} login success ".format(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
    except:
        print("[00] {} Requsest error, raspberry isnot connected to WIFI".format(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
Copy the code

Run the script with a batch file

@echo off
python E:\PycharmProjects\demo\Python\login\login.py
pause
Copy the code

Detailed code

This code has been uploaded to Github github.com/ljr7822/iwe…

conclusion

Python used less than 40 lines of code to implement automatic login. I have to admire the power of Python. Although this was a very simple demo, I learned a lot from this project