寫了一個登錄新版TUNet的腳本,因為是一邊翻書一邊寫的,所以非常挫,不過應該能用。
寫這個最初目的是做嵌入式的大作業的,因為TUNet更新了,所以不能做以前的那個mytunet的交叉編譯了。。。
腳本在Openwrt上測試通過。
把腳本中的your_username替換成info的用戶名,your_password_md5替換成你的密碼的md5,可以用echo -n your_password | md5sum來得到。另外腳本需要curl,Ubuntu用戶可以用sudo apt-get install curl來安裝。
代碼如下:
- #!/bin/bash
- # your info's username
- uname=your_username
- # your info's password's md5sum
- pass=your_password_md5
- ####################################################
- do_login() {
- login_data='username='$uname'&password='$pass'&drop=0&type=1&n=100'
- check_data='action=check_online'
-
- # check whether already online
- con=`curl -d $check_data -s http://net.tsinghua.edu.cn/cgi-bin/do_login`
-
- if [ -z $con ]; then
- # start login
- res=`curl -d $login_data -s http://net.tsinghua.edu.cn/cgi-bin/do_login`
-
- #handle result
- pe=`echo $res | grep error`
- if [ -z $pe ]; then
- echo "Login Success!"
- else
- echo $pe
- exit 0
- fi
-
- # display flux infomation
- flux=`echo $res | awk -F ',' '{print $3}'`
- a=$(($flux/1000000000))
- b=$((($flux%1000000000)/100000000))
- c=$((($flux%100000000)/10000000))
- echo "Used Flux: "$a"."$b$c"G."
-
- else
- echo "Already Online!"
-
- # display flux information and online time
- flux=`echo $con | awk -F ',' '{print $3}'`
- time=`echo $con | awk -F ',' '{print $5}'`
- a=$(($flux/1000000000))
- b=$((($flux%1000000000)/100000000))
- c=$((($flux%100000000)/10000000))
- h=$(($time/3600))
- m=$(($(($time%3600))/60))
- s=$(($(($time%3600))%60))
- echo "Used Flux: "$a"."$b$c"G, Online Time: "$h":"$m":"$s"."
- fi
- }
-
- do_logout() {
- # start logout
- res=`curl -s http://net.tsinghua.edu.cn/cgi-bin/do_logout`
-
- #handle result
- if [ "$res" == "logout_ok" ]; then
- echo "Logout Success!"
- elif [ "$res" == "not_online_error" ]; then
- echo "You're not Online!"
- else
- echo "Operation Failed!"
- fi
- }
-
- ##################################################################################
- if [ "$1" == "login" ]; then
- do_login
- elif [ "$1" == "logout" ]; then
- do_logout
- else
- echo "Usage: "$0" {login|logout}"
- fi