由于TP-Link路由器 便携式的那种小的,有时候长时间不重启的话。感觉网站打开很慢。所以想让他每天重启一下。在tplink的页面里没有找到这样的功能,于是想到用python来做一个定时任务来让tplink重启。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# -*- coding: utf-8 -*- # 重启路由器脚本 # import urllib2, base64 # 192.168.1.1 # admin:admin (BASE64编码) if __name__ == '__main__': # 请求地址 url = 'http://192.168.10.88/userRpm/SysRebootRpm.htm?Reboot=重启路由器' # 验证的用户名和密码 login_user = 'admin' login_pw = 'admin' auth = 'Basic ' + base64.b64encode('admin:admin') print auth heads = { 'Referer' : 'http://192.168.10.88/userRpm/SysRebootRpm.htm', 'Authorization' : auth } # 请求重启路由器 request = urllib2.Request(url, None, heads) response = urllib2.urlopen(request) print response.read() |
crontab -e
1 |
0 3 * * * /usr/bin/python /root/rtplink.py |
每天晚上3点重启一下路由器。
如果没有linux python的环境,在windows上也可以写一个vbs 做计划任务来实现。下面的代码保存为.vbs ,做定时任务就可以。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
user = "admin" '路由器帐号 pass = "admin" '路由器密码 With CreateObject("Msxml2.ServerXMLHTTP") .open "GET", "http://192.168.10.88/userRpm/SysRebootRpm.htm?Reboot=重启路由器", False, user, pass .send End With MsgBox "命令已发出,60秒内重启完毕。", 64, "重启路由器" |