Skip to content

Instantly share code, notes, and snippets.

@darren
Last active November 30, 2023 05:04
Show Gist options
  • Save darren/ca7e8bfa44ddd27d472f to your computer and use it in GitHub Desktop.
Save darren/ca7e8bfa44ddd27d472f to your computer and use it in GitHub Desktop.
国家图书馆Wifi自动登录脚本
#!/usr/bin/env bash
USERNAME= #改成你的读者卡号
PASSWORD= #改成你的读者卡密码
LOGINURL="http://192.168.180.11:8080/nlcwlan/QueryGuest"
PASSWORD=$(echo $PASSWORD|base64)
UA="Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"
function test_conn {
server=$1
ping -c 3 -t 5 $server >/dev/null 2>&1
res=$?
if [[ $res == 0 ]] ;then
return $res
else
return -1
fi
}
function try_conn {
res=$(curl -d "id_userPwd=$PASSWORD&id_userName=$USERNAME" "$LOGINURL" --user-agent "$UA" 2>/dev/null)
if [[ $res =~ "success" ]]; then
printf "\x1b[1;33mo\x1b[m" # o
else
printf "\x1b[3;31m!\x1b[m" # !
fi
}
let i=0
while :; do
let 'o=i%16, i=i+1'
if test_conn 60.247.28.1; then
[ $o -eq 0 ] && printf "\x1b[32m.\x1b[m" # .
elif test_conn 192.168.180.11; then
# Login server is OK
# echo "No Connection, try Connect"
try_conn
else
#echo "No Connection and login Server not available"
[ $o -eq 0 ] && printf "\x1b[1;31mx\x1b[m" # x
fi
sleep 1
done
exit 0;
@KJlmfe
Copy link

KJlmfe commented Jan 27, 2016

赞!刚好在国图,不过国图略啃爹,一个账号最多只能同时一台设备登陆。手机、电脑没法同时用。。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment