ficapy
12/15/2015 - 10:46 AM

小米路由器重启脚本,万一有人会用到呢

小米路由器重启脚本,万一有人会用到呢

import time
import random
import requests
from hashlib import sha1

key = 'a2ffa5c9be0748*********'  # 登陆页面查看源码获得
deviceId = '98:5a:eb:*****'
pwd = '*************'
url = 'http://192.168.31.1/cgi-bin/luci/api/xqsystem/login'
reboot_url = 'http://192.168.31.1/cgi-bin/luci/;stok={}/api/xqsystem/reboot?client=web'

random_number = '_'.join(map(str, [0, deviceId, int(time.time()), int(random.random() * 10000)]))
password = sha1(random_number + sha1(pwd + key).hexdigest()).hexdigest()
ret = requests.post(url, data={'username': 'admin',
                               'password': password,
                               'logtype': '2',
                               'nonce': random_number})

token = ret.json()['token']
requests.get(reboot_url.format(token))