鱼C论坛

 找回密码
 立即注册
查看: 4674|回复: 2

【急】小米路由器重新拨号的Python 求解

[复制链接]
发表于 2017-5-25 09:31:32 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. # -*- coding: utf-8 -*-
  2. import requests
  3. import urllib
  4. from Crypto.Hash import SHA
  5. import time
  6. import json
  7. import re
  8. import random
  9. import datetime


  10. class Adsl():
  11.     def __init__(self):
  12.         self.host = '192.168.31.1/'
  13.         self.username = 'admin'
  14.         self.password = 'huangxin250'

  15.     def connect(self):
  16.         host = self.host
  17.         homeRequest = requests.get('http://' + host + '/cgi-bin/luci/web/home')
  18.         key = re.findall(r'key: \'(.*)\',', homeRequest.text)[0]
  19.         mac = re.findall(r'deviceId = \'(.*)\';', homeRequest.text)[0]
  20.         aimurl = "http://" + host + "/cgi-bin/luci/api/xqsystem/login"
  21.         nonce = "0_" + mac + "_" + str(int(time.time())) + "_" + str(random.randint(1000, 10000))
  22.         pwdtext = self.password
  23.         pwd = SHA.new()
  24.         pwd.update(pwdtext + key)
  25.         hexpwd1 = pwd.hexdigest()
  26.         pwd2 = SHA.new()
  27.         pwd2.update(nonce + hexpwd1)
  28.         hexpwd2 = pwd2.hexdigest()
  29.         data = {
  30.             "logtype": 2,
  31.             "nonce": nonce,
  32.             "password": hexpwd2,
  33.             "username": self.username
  34.         }
  35.         response = requests.post(url=aimurl, data=data, timeout=15)
  36.         resjson = json.loads(response.content)
  37.         token = resjson['token']
  38.         webstop = urllib.urlopen('http://192.168.31.1/cgi-bin/luci/;stok=' + token + '/api/xqnetwork/pppoe_stop')
  39.         #time.sleep(1)
  40.         webstart = urllib.urlopen('http://192.168.31.1/cgi-bin/luci/;stok=' + token + '/api/xqnetwork/pppoe_start')
  41.         date = datetime.datetime.now()
  42.         nowtime = str(date)[:-10]
  43.         print nowtime + ', congratulations, the IP is changed !'
复制代码


已上代码来自“蚍蜉撼大树”。
我还是小白,所有对什么代码不理解,急需使用,请教下需要修改那些可以直接使用!谢谢
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2017-5-25 16:09:03 | 显示全部楼层
好安静哦~
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-5-25 18:30:46 | 显示全部楼层
看起来好像只需要该init部分,还有下面的路由器页面也要改。
然后 还要做一个运行的部分代码。
如果基础不行,你应该一时半会儿是用不了这个代码的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-12-21 16:47

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表