How to login in WLT in shell

 

Here is the simple script to login WLT which allows you to access network in USTC campus. Please append on name= and pass= with your own account name and password. It works well on Linux system. For more, try to modify it by yourself.

#!/bin/bash
url=http://wlt.ustc.edu.cn/cgi-bin/ip
tmpf=/tmp/wlt$RANDOM

function print_status {
    ! text=`curl -b $tmpf -s $url` && echo "\033[01;31mFail to access wlt.ustc.edu.cn\033[0m" && exit
    grep -q 'cmd=logout' <<< $text && echo -e "\033[01;32mYour have logged in\033[0m" && iconv -f gb2312 -t utf-8 - <<< $text | sed 's/.*border=0 width=620 cellspacing=0 bordercolor="#cccccc"><tr><td>//g;s|</td>.*||g;s/<br>/ /g'
    grep -q 'type=password' <<< $text && echo -e "\033[01;33mPlease login\033[0m"
    grep -q 'font color="red"' <<< $text && echo -e "\033[01;31mYour are not in USTC-LAN\033[0m"
}

print_status

name=
pass=
touch $tmpf
echo
curl -c $tmpf "$url?cmd=login&name=$name&password=$pass&520" > /dev/null
curl -b $tmpf "$url?cmd=set&type=8&exp=0" > /dev/null

print_status
rm $tmpf