#思路:
##1、 当校园网断开,只需要重新拨号即可
##2、 校园网使用两台电脑同时登录时不会立即下线,其中有一段时间间隔
#步骤:
##1、 通过抓包对拨号产生的数据包进行分析,使得可以通过代码来实现自动拨号
脚本一(login.sh):
#!/bin/bash # check Internet status sleep 20 ping -c 1 114.114.114.114 > /dev/null 2>&1 if [ $? -eq 0 ];then logger Connecting. else logger Network disconnection. source ./login.sh # 等价于 ../login.sh 使用source调用脚本不会退出当前脚本 logger Reconnecting.
这个脚本的作用是用于断网检测
脚本二(check_net.sh):
#!/bin/bash logger "[Dr.com page verify] Start timing detection." curl http://192.168.167.46 >drcom.html check_status=`grep "Dr.COMWebLoginID_0.htm" drcom.html` if [[ $check_status != "" ]] then # offline status logger "[Dr.com page verify] offline status." # yourself curl curl -X POST "http://192.168.167.46/a70.htm" -H "Origin: http://192.168.167.46" -H "Connection: keep-a live" -H "Content-Type: application/x-www-form-urlencoded" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.170 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" -H "DNT: 1" -H "http://192.168.167.46/a70.htm?wlanacip=null&wlanacname=null&vlanid=0&ssid=null&areaID=null&mac=00-00-00-00-00-00" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: zh-CN,zh;q=0.9" -b "program=ip; vlan=0; ip=10.73.42.253; md5_login2=1809111038%7C284974" --data "DDDDD=1809111038&upass=284974&R1=0&R2=&R6=0¶=00&0MKKey=123456&buttonClicked=&redirect_url=&err_flag=&username=&password=&user=&cmd=&Login=&R7=0" --tlsv1 -o Sxinfo.txt logger "[Dr.com page verify] online status." else # always online logger "[Dr.com page verify] already onine." fi
##2、 如果需要实现多台电脑同时在线,就需要在校园网还没检测并下线之前重新拨号
对于上面的脚本进行任务计划,将时间间隔设置在11秒(防止拨号频繁被禁)
*/1 * * * * sleep 11 && /etc/storage/login.sh */1 * * * * sleep 23 && /etc/storage/login.sh */1 * * * * sleep 35 && /etc/storage/login.sh */1 * * * * sleep 47 && /etc/storage/login.sh */1 * * * * sleep 58 && /etc/storage/login.sh
#优化:
##1、 不知道为啥,校园网偶尔需要重新拨号,所以我写了一个脚本来以防万一;
并且把计划任务自动化,因为一停电路由器就会初始化=,=
ps:来自一个月后的我终于知道了,把脚本放到etc下就不会因为断电重启刷掉了
脚本三:
#!/bin/bash a=`wc -l /etc/storage/cron/crontabs/admin |awk 'BEGINF{FS=""}{print $1}'` b=7 c=`ping -c 3 www.baidu.com | grep loss | awk 'BEGIN{FS=","} {print $3}'| awk 'BEGIN{FS="%"} {print $1}'` d=0 if [ a!=b ];then rm -rf /home/root/admin echo "*/1 0-23 * * 1-7 /etc/storage/check_net.sh" >>/home/root/admin echo "*/1 * * * * sleep 11 && /etc/storage/login.sh" >>/home/root/admin echo "*/1 * * * * sleep 23 && /etc/storage/login.sh" >>/home/root/admin echo "*/1 * * * * sleep 35 && /etc/storage/login.sh" >>/home/root/admin echo "*/1 * * * * sleep 47 && /etc/storage/login.sh" >>/home/root/admin echo "*/1 * * * * sleep 58 && /etc/storage/login.sh" >>/home/root/admin echo "*/1 0-23 * * 1-7 /home/root/test.sh" >>/home/root/admin rm -rf /etc/storage/cron/crontabs/admin mv /home/root/admin /etc/storage/cron/crontabs/ if [ c!=d ];then sh /etc/storage/login.sh fi fi
*注:主要作用就是
1、检查计划任务是不是正常的,不是就重新写入。
2、ping一下百度,要是没有ping通就重新执行一下脚本(这个脚本我给他设置的计划任务时间间隔是一分钟)
#自动化脚本:
接下来是重头戏,因为需要帮其他同学搞所以我就把所有脚本写一起了,经过几次的迭代优化。可能还是会有一些小毛病。
#!/bin/bash while true do clear echo "菜单" echo "1 检测网络" echo "2 清理计划任务" echo "3 部署破解脚本" echo "4 退出脚本" read -p "请选择模式:" mode case $mode in 1) echo "您选择了模式1-检测网络" echo "正在为您检测网络" a=`ping -c 3 www.baidu.com | grep loss | awk 'BEGIN{FS=","} {print $3}'| awk 'BEGIN{FS="%"} {print $1}'` b=0 if [ $a == $b ];then #echo "您的网络正常" echo -e "