Skip to content

Instantly share code, notes, and snippets.

@ninehills
Created November 23, 2010 16:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ninehills/712008 to your computer and use it in GitHub Desktop.
Save ninehills/712008 to your computer and use it in GitHub Desktop.
南开大学网关自动登录脚本
#!/bin/bash
#-------------------------------
# 南开大学网关自动登录脚本
# 用法请用help命令查询
# 支持ipv4/ipv6登录
# 作者:cynic<cynic AT 9hills.us>
# 网站:http://9hills.us
# cygwin下测试通过
#-------------------------------
USER=username #账号
PASS=password #密码
# ipv4网关
GATE=https://202.113.18.188
GATE_LOGOUT=https://202.113.18.188/F.htm #网关登出地址
# 第二个网关
GATE2=https://202.113.18.180
GATE_LOGOUT2=https://202.113.18.180/F.htm #网关登出地址
# ipv6网关
IPV6_GATE=https://ip6.nku.cn
IPV6_GATE_LOGOUT=https://ip6.nku.cn/F.htm
if [ -z "$1" ]
then
echo "Usage: `basename $0` [login|logout|show|help] [v41|v42|v6]"
exit
fi
if [ "$2" = "v42" ];
then
GATE=$GATE2;
GATE_LOGOUT=$GATE_LOGOUT2;
fi
if [ "$2" = "v6" ];
then
GATE=$IPV6_GATE;
GATE_LOGOUT=$IPV6_GATE_LOGOUT;
fi
if [ "$1" = "login" ];
then
not_login=`curl -silent -k -d DDDDD=$USER -d upass=$PASS -d 0MKKey='登录 Login' $GATE | grep -c 'Msg=01'`
if [ 0 -ne $not_login ]
then
echo -e "\E[1;31mWrong Username or Password! \E[0m"
exit
fi
exit
fi
if [ "$1" = "show" ];
then
is_logout=`curl -silent -k $GATE | grep -c '0MKKey'`
if [ 0 -ne $is_logout ]
then
echo -e "\E[1;31mNot Login \E[0m"
exit
fi
result1=`curl -silent -k $GATE | grep 'uid='`
result2=`curl -silent -k $GATE | grep 'fee='`
# 账号ID
user_id=`echo $result1 | awk -F\' '{print $2}'`
#登录IP
login_ip=`echo $result1| awk -F\' '{print $6}'`
if [ "$2" = "v6" ];
then
#显示ipv6的ip地址
login_ip=`echo $result1 | awk -F\' '{print $8}'`
fi
# 本账号已使用时间,单位min
use_time=`echo $result2 | awk -F\' '{print $2}'`
# 本帐号已使用流量,单位MB
flow=`echo $result2 | awk -F\' '{print $4/1024}'`
# 当前余额,单位RMB
fee=`echo $result2 | awk -F\' '{print $6/10000}'`
echo '=================================================='
echo '您登录进的网关为' $GATE
echo '您的账号为' $user_id
echo '登录IP地址为' $login_ip
echo 'ipv4帐号已使用时间为 '$use_time' 分钟'
echo 'ipv4已使用流量为 '$flow' MB'
echo 'ipv4余额为 '$fee' 元'
echo '=================================================='
exit
fi
if [ "$1" = "logout" ];
then
is_logout=`curl -silent -k $GATE_LOGOUT | grep -c 'Msg=14'`
exit
fi
echo '---------------------------------------------------'
echo -e "\E[1;31m gateway.sh 使用帮助 \E[0m"
echo '---------------------------------------------------'
echo -e "\E[1;31m使用方法: \E[0m"
echo "`basename $0` [login|logout|show|help] [v41|v42|v6]"
echo '---------------------------------------------------'
echo 'login: 登入 '
echo 'logout: 登出 '
echo 'show: 显示账号信息'
echo '---------------------------------------------------'
echo 'v41: 188网关(默认)'
echo 'v42: 180网关 '
echo 'v6: ipv6网关 '
echo '---------------------------------------------------'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment