|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- # -*- coding: utf-8 -*-
- import requests
- import urllib
- from Crypto.Hash import SHA
- import time
- import json
- import re
- import random
- import datetime
-
-
- class Adsl():
- def __init__(self):
- self.host = '192.168.31.1/'
- self.username = 'admin'
- self.password = 'huangxin250'
-
- def connect(self):
- host = self.host
- homeRequest = requests.get('http://' + host + '/cgi-bin/luci/web/home')
- key = re.findall(r'key: \'(.*)\',', homeRequest.text)[0]
- mac = re.findall(r'deviceId = \'(.*)\';', homeRequest.text)[0]
- aimurl = "http://" + host + "/cgi-bin/luci/api/xqsystem/login"
- nonce = "0_" + mac + "_" + str(int(time.time())) + "_" + str(random.randint(1000, 10000))
- pwdtext = self.password
- pwd = SHA.new()
- pwd.update(pwdtext + key)
- hexpwd1 = pwd.hexdigest()
- pwd2 = SHA.new()
- pwd2.update(nonce + hexpwd1)
- hexpwd2 = pwd2.hexdigest()
- data = {
- "logtype": 2,
- "nonce": nonce,
- "password": hexpwd2,
- "username": self.username
- }
- response = requests.post(url=aimurl, data=data, timeout=15)
- resjson = json.loads(response.content)
- token = resjson['token']
- webstop = urllib.urlopen('http://192.168.31.1/cgi-bin/luci/;stok=' + token + '/api/xqnetwork/pppoe_stop')
- #time.sleep(1)
- webstart = urllib.urlopen('http://192.168.31.1/cgi-bin/luci/;stok=' + token + '/api/xqnetwork/pppoe_start')
- date = datetime.datetime.now()
- nowtime = str(date)[:-10]
- print nowtime + ', congratulations, the IP is changed !'
复制代码
已上代码来自“蚍蜉撼大树”。
我还是小白,所有对什么代码不理解,急需使用,请教下需要修改那些可以直接使用!谢谢 |
|