Campus Network Connection Script

Words 322
Views
Visitors

Timeline

Timeline

2025-10-09

init

This article introduces the specific operation process for connecting a Raspberry Pi to the campus network, including configuring wireless network parameters, verifying IP connection status, and troubleshooting failure logs. It also summarizes the steps to write and run an authentication script through packet capture technology to achieve automatic network authentication and login.

First enable wlan, then let wlan connect to the campus network, the Raspberry Pi can be used

1
sudo raspi-config

Then in the System Option, enter the ssid and passphrase in Wireless LAN

Or write to /etc/wpa_supplicant/wpa_supplicant.conf

1
2
3
4
5
6
7
8
ctrl_interface=DIR=/run/wpa_supplicant GROUP=netdev
update_config=1
country=CN

network={
ssid="HNU"
key_mgmt=NONE
}

Then restart the wpa_supplicant service

1
sudo systemctl restart wpa_supplicant

After the above operations, use the ifconfig command to check if the inet of wlan has an IP address. If it does, it means the campus network has been connected, and the next step is to pass the authentication.

If it is not successful, call the following command to view the logs

1
journalctl -u wpa_supplicant -n 50 --no-pager

Packet capture:

Fiddler packet capture
Fiddler packet capture

Through packet capture, the following script can be written:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# First get the IPv4 and MAC of wlan0
IP=$(ip -4 -o addr show wlan0 | awk '{print $4}' | cut -d/ -f1)
MAC=$(cat /sys/class/net/wlan0/address)


USER=",0,your_student_number"
PASS="your_password"

curl -s --get "https://web.hnu.edu.cn:802/eportal/portal/login" \
--data-urlencode "callback=dr1003" \
--data-urlencode "login_method=1" \
--data-urlencode "user_account=${USER}" \
--data-urlencode "user_password=${PASS}" \
--data-urlencode "wlan_user_ip=${IP}" \
--data-urlencode "wlan_user_mac=${MAC}" \
--data-urlencode "terminal_type=1" \
--insecure \
-D - \
| sed -n '1,200p'

After running the above script, test whether the connection is successful

1
ping www.baidu.com