背景:家里光猫经常断网,重启才能恢复。
光猫位置拔电源不方便,telnet登录重启需破解有风险,因此采用curl模拟登录web重启。最后通过其他脚本监测,实现断网时自动执行重启。
#!/bin/sha=$1 loginfo=`curl -s -L http://192.168.1.1/cgi-bin/luci -X POST -c /mnt/sdcard/myscript/cookies.txt -d 'username=用户名&psd=密码'`function mygetip() {ipinfo=`curl -s -b /mnt/sdcard/myscript/cookies.txt http://192.168.1.1/cgi-bin/luci/admin/settings/gwinfo?get=part&_=0.4801976069522096`echo $ipinfo | sed 's/,/\n/g' | grep -w WANIP}function myrestart() {runt=`curl -s -b /mnt/sdcard/myscript/cookies.txt http://192.168.1.1/cgi-bin/luci/admin/settings/gwstatus?_=0.5191398782674221 | sed 's/,/\n/g' | awk -F ':' '/sysTime/{print $2}'`if [ $runt -lt 120 ]; then echo -e "wating start..." else mytoken=$(echo $loginfo |sed 's/{/\n/g' | grep token |awk '/realRestart/{print $2}'| sed $'s/\'//g') curl -s -b /mnt/sdcard/myscript/cookies.txt http://192.168.1.1/cgi-bin/luci/admin/reboot -d 'token='$mytoken echo -e "Restating..." fi} if [ $a == 'restart' ]; thenif ping -W 3 -c 1 114.114.114.114 >/dev/null 2>&1thenmygetipelsemyrestartfielif [ $a == 'getip' ]; thenmygetip elseexitfiexit