Skip to content

Instantly share code, notes, and snippets.

@NevadaCities
Last active November 10, 2025 04:11
Show Gist options
  • Select an option

  • Save NevadaCities/347e1482f3ed778418ce6384445b5cf5 to your computer and use it in GitHub Desktop.

Select an option

Save NevadaCities/347e1482f3ed778418ce6384445b5cf5 to your computer and use it in GitHub Desktop.
NFDX Campus Network Authentication Scripts for OpenWRT.
#!/usr/bin/env ash
phone_number="<your_phone_number>"
password="<your_password>"
interface="<your_interface>"
echo "Waiting for IP address on interface ${interface}..." >&2
max_attempts=30
attempt=0
while [ -z "$ip" ] && [ $attempt -lt $max_attempts ]; do
ip=$(ip addr | awk -v iface_name="$interface" '/^[0-9]+:/{iface=$2; sub(/:$/,"",iface)} iface==iface_name && /inet /{split($2,a,"/"); print a[1]; exit}')
if [ -z "$ip" ]; then
sleep 1
attempt=$((attempt+1))
echo "Attempt ${attempt}: Still no IP. Retrying..." >&2
fi
done
if [ -z "$ip" ]; then
echo "Error: Could not get IP address for interface ${interface} after ${max_attempts} attempts. Exiting." >&2
exit 1
fi
mac=$(ip addr | awk -v iface_name="$interface" '/^[0-9]+:/{iface=$2; sub(/:$/,"",iface)} iface==iface_name && /link\/ether/{print $2; exit}')
echo "ip = ${ip}"
echo "mac = ${mac}"
curl_command="curl -X POST \"http://192.1.1.55:801/eportal/?c=ACSetting&a=Login&protocol=http:&hostname=192.1.1.55&iTermType=1&wlanuserip=${ip}&wlanacip=null&wlanacname=null&mac=${mac}&ip=${ip}&enAdvert=0&queryACIP=0&jsVersion=2.4.3&loginMethod=1\" -H \"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36\" -H \"Content-Type: application/x-www-form-urlencoded\" -H \"Referer: http://192.1.1.55/\" --data-raw \"DDDDD=%2C0%2C${phone_number}%40unicom&upass=${password}&R1=0&R2=0&R3=0&R6=0&para=00&0MKKey=123456&buttonClicked=&redirect_url=&err_flag=&username=&password=&user=&cmd=&Login=&v6ip=\" -v"
curl_raw_output=$(mktemp)
location_query_string_tmp=$(mktemp)
parsed_error_params_tmp=$(mktemp)
trap "rm -f \"$curl_raw_output\" \"$location_query_string_tmp\" \"$parsed_error_params_tmp\"" EXIT
eval "$curl_command" 2>&1 | \
tee "$curl_raw_output" | \
grep -E '^< Location:' > "$location_query_string_tmp"
location_query=$(cat "$location_query_string_tmp")
if echo "$location_query" | grep -q "3.htm"; then
echo "Authentication successful."
exit 0
else
echo "$location_query" | \
sed -E 's/.*ACLogOut=([^&]*).*RetCode=([^&]*).*ErrorMsg=([^&]*).*/ACLogOut: \1\nRetCode: \2\nErrorMsg: \3/' > "$parsed_error_params_tmp"
parsed_params_content=$(cat "$parsed_error_params_tmp")
if [ -n "$parsed_params_content" ]; then
echo "Authentication failed:"
echo "${parsed_params_content}"
exit 1
elif [ -n "$location_query" ]; then
echo "Authentication failed due to unknown reason. Location header query: ${location_query}"
exit 1
else
echo "Authentication failed: No relevant Location header or query string found to confirm success, and no explicit error messages were detected."
exit 1
fi
fi
#!/bin/sh /etc/rc.common
USE_PROCD=1
START=99
STOP=01
start_service() {
procd_open_instance
procd_set_param command /bin/sh "/root/auth.sh"
procd_set_param pidfile /var/run/auth_sh.pid
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
59 23 */3 * * > /var/log/auth_sh.log
0 */3 * * * /root/auth.sh 2>&1 | /usr/bin/awk '{ print strftime("%Y-%m-%d %H:%M:%S", systime()) " " $0; fflush(); }' >> /var/log/auth_sh.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment