Loading

TPLINK路由器重启脚本(软件版本3.0.0)

​ 家中的两个路由器全都是TPLink路由器,由于总出现时间一长就网卡的原因,写了这个重启脚本在每天凌晨五点的时候对路由器进行自动重启

使用方法:

self.logindata的值为登录时的json数据

​ 打开F12控制台,复制登陆的json数据包并填入self.logindata

import requests
from datetime import datetime
import time

class TPLINK:
    def __init__(self,ip:str):
        self.ip=ip
        self.logindata={"method":"do","login":{"password":"W3MVrwxv74U8KT8"}}  #需要复制自己的登录数据

    def login(self):
        resp=requests.post(url='http://'+self.ip,json=self.logindata)
        if resp.status_code==200 and resp.json()['error_code']==0:
            print('get stok success , stok='+resp.json()['stok'])
            return resp.json()['stok']
        else:
            print(self.ip+'出现登录错误')

    def reboot(self):
        json_data={"system":{"reboot":None},"method":"do"}
        resp=requests.post(url='http://'+self.ip+'/stok={0}/ds'.format(self.login()),json=json_data)
        if resp.status_code==200 and resp.json()['error_code']==0:
            print(self.ip+' reboot success')
            print(resp.text)


if __name__=='__main__':
    while True:
        current_time = datetime.now().time()
        if current_time.hour == 5 and current_time.minute == 0:
            r1=TPLINK(ip='192.168.1.1')  #填写自己的路由器IP
            r1.reboot()
            time.sleep(60)
            r2=TPLINK(ip='192.168.0.1')  #填写自己的路由器IP
            r2.reboot()
        else:
            time.sleep(30)

使用效果:

posted @ 2024-01-24 16:45  k1115h0t  阅读(41)  评论(0编辑  收藏  举报