技巧篇

openwrt自动web认证cmcc

#!/bin/sh
##firewall script for initial login
#echo "/root/relogin2.sh >/tmp/relogin2.log" >> /etc/firewall.user
##cronjob for keepalive and auto relogin (range(-) not supported on OpenWrt??)
##/etc/init.d/cron reload
## m h  dom mon dow   command
#*/3 * * * * killall wget;wget http://www.openwrt.com.cn -O /dev/null >/tmp/keepalive.log 2>&1 &
#0 */6 * * * /root/relogin2.sh >/tmp/relogin2.log 2>&1 &
export PATH=.:$PATH
cd /root
date "+%Y-%m-%d %H:%M:%S"
#Fake UA should be better 😉
user_agent="Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"
uci set network.wwan.username=13888888888
uci set network.wwan.password=888888
##uci commit
bpssUSERNAME=$(uci get network.wwan.username)
bpssBUSPWD=$(uci get network.wwan.password)
#echo $bpssUSERNAME $bpssBUSPWD
#opkg update
#opkg install wget #curl
if [ -e login_res.html ]
then
base_url=$(cat login_res.html|grep "base href"|awk -F'"' '{print $2}')
logout_url1=$(cat login_res.html|grep "LogoutServlet"|awk -F'"' '{print $2}')
logout_url2=$(cat login_res.html|grep "ATTRIBUTE_UUID"|awk -F'"' '{print $2}')
logout_url3=$(cat login_res.html|grep "ATTRIBUTE_IPADDRESS"|awk -F'"' '{print $2}')
#echo "${base_url}${logout_url1}${logout_url2}${logout_url3}1"
#logout_res
wget "${base_url}${logout_url1}${logout_url2}${logout_url3}1" -O logout_res.html -U "${user_agent}" --no-check-certificate
cat logout_res.html
fi
#下班后不再登陆
if [ date "+%H" -gt 18 -o -e nologin ] then echo "Off duty. No login until 8:00 next weekday." exit fi #login_pre wget "http://www.google.com/" -O login_pre.html -U "${user_agent}" action_url=$(cat login_pre.html|grep "form action"|awk -F'"' '{print $2}'|head -1) wlanuserip_1=$(cat login_pre.html|grep "wlanuserip_1"|awk -F'"' '{print $8}'|head -1) wlanacname_1=$(cat login_pre.html|grep "wlanacname_1"|awk -F'"' '{print $8}'|head -1) wlanparameter_1=$(cat login_pre.html|grep "wlanparameter_1"|awk -F'"' '{print $8}'|head -1) #echo ${action_url} #echo ${wlanuserip_1} ${wlanacname_1} ${wlanparameter_1} ##login_res, post #wget "${action_url}" -O login_res.html -U "${user_agent}" --no-check-certificate \ #--post-data="bpssUSERNAME=${bpssUSERNAME}&bpssBUSPWD=${bpssBUSPWD}&wlanuserip_1=${wlanuserip_1}&wlanacname_1=${wlanacname_1}&wlanparameter_1=${wlanparameter_1}&wlanuserfirsturl_1=http://www.google.com/&ssid_1=&userAgent_1=${user_agent}&usertype_1=pc&gotopage_1=/cmccpc.jsp&css_1=/css/cmccpc_include.css&sucesspage_1=/cmccpc_index.jsp&cookieage=1&loginmode=static&wlanacssid=&issaveinfo=" ##get is fine wget "${action_url}?bpssUSERNAME=${bpssUSERNAME}&bpssBUSPWD=${bpssBUSPWD}&wlanuserip_1=${wlanuserip_1}&wlanacname_1=${wlanacname_1}&wlanparameter_1=${wlanparameter_1}&wlanuserfirsturl_1=http://www.google.com/&ssid_1=&userAgent_1=${user_agent}&usertype_1=pc&gotopage_1=/cmccpc.jsp&css_1=/css/cmccpc_include.css&sucesspage_1=/cmccpc_index.jsp&cookieage=1&loginmode=static&wlanacssid=&issaveinfo=" -O login_res.html -U "${user_agent}" --no-check-certificate grep "loginsuccess" login_res.html date "+%Y-%m-%d %H:%M:%S"