FunnyWeb

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

openwrt自动重连chinaunicom脚本

2017-04-27 11:28:22856 views

python版本亲测可用:

import urllib2
import os
import time

username='132xxxxxxxx'
password='xxxxxx'
location='bj'

print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 
try:
    ret=urllib2.urlopen('http://zhuhd.win/other/checknet.php',timeout=2).read()
except:
    ret=''
if(ret!='1'):
    os.system('/sbin/restart_wan') #重新连接命令 根据系统不同可修改
    time.sleep(15)
    ret='null'
    url='http://202.106.46.37/login.do?callback=jQuery17105693262386309437_1491889696870&username='+username+'&password='+password+'&passwordType=6&wlanuserip=&userOpenAddress='+location+'&checkbox=0&basname=&setUserOnline=&sap=&macAddr=&bandMacAuth=0&isMacAuth=&basPushUrl=http%253A%252F%252F202.106.46.37%252F&passwordkey=&adPage=http%3A%2F%2Factivity.114menhu.com%2Fwifiad&_=1491889734063'
    try:  
        conn=urllib2.urlopen(url, timeout = 1)
        ret=conn.read()  
    except:  
        ret='timeout...'
    print ret
else:
    print 'connected...'

shell版本:

2017.5.28测试可用

需要修改手机号,密码,开户地为正确信息。其中开户地是拼音首字母,比如bj,sd...

#!/bin/sh

date +%F" "%H:%M:%S
if ping -w 1 -c 1 114.114.114.114
  then 
    echo 'connected..'
  else 
    wget -c 'http://202.106.46.37/login.do?callback=jQuery17105693262386309437_1491889696870&username=186xxxxxxxx&password=xxxxxx&passwordType=6&wlanuserip=&userOpenAddress=bj&checkbox=0&basname=&setUserOnline=&sap=&macAddr=&bandMacAuth=0&isMacAuth=&basPushUrl=http%253A%252F%252F202.106.46.37%252F&passwordkey=&adPage=http%3A%2F%2Factivity.114menhu.com%2Fwifiad&_=1491889734063' -O /tmp/cnet.tmp
    if ping -w 1 -c 1 114.114.114.114
    then
      echo 'connected...'
    else
      echo 'timeout...'
    fi
fi

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

然后

crontab -e

添加计划任务即可

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