FunnyWeb

据说这里有很多神奇的东西...

openwrt自动重连UCAS脚本

2017-08-23 12:48:302286 views

Python版本:

#coding:utf-8
import urllib
import json

def login(userId, password):
    loginUrl='http://210.77.16.21/eportal/InterFace.do?method=login&userId='+userId+'&password='+password+'&service=&queryString=1&operatorPwd=&validcode='
    conn = urllib.urlopen(loginUrl)
    html = conn.read().decode("utf8")
    result = json.loads(html)
    if result['result'] == 'success':
        print "success..."
    else:
        print "fail..."
    return result

try:
    ret=urllib2.urlopen('http://zhuhd.win/other/checknet.php',timeout=2).read()
except:
    ret=''
if(ret!='1'):
    login("****************","******")
else:
    print "connected..."

shell版本:

#!/bin/sh
date
if ping -w 1 -c 1 114.114.114.114
then
    echo 'connected..'
else 
    username="****************"
    password="******"
    url="http://210.77.16.21/eportal/InterFace.do?method=login&userId="$username"&password="$password"&service=&queryString=1&operatorPwd=&validcode="
    res=$(curl $url)
    result=$(echo $res | grep "\"result\":\"success\"")
        if [[ "$result" != "" ]]
    then
        echo "success..."
    else
        echo "fail..."
    fi
fi

编辑好文件后保存到/opt/etc/zgcnet.sh

然后

crontab -e

添加计划任务即可

*/2 * * * * /opt/etc/zgcnet.sh >> /opt/tmp/zgcnet.sh.tmp 2>&1