Skip to content

Instantly share code, notes, and snippets.

@ficapy
Created December 15, 2015 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ficapy/271a2d61cd881b91be5a to your computer and use it in GitHub Desktop.
Save ficapy/271a2d61cd881b91be5a to your computer and use it in GitHub Desktop.
小米路由器重启脚本,万一有人会用到呢
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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment