-
Notifications
You must be signed in to change notification settings - Fork 0
/
python router.py
54 lines (45 loc) · 1.25 KB
/
python router.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#coding=utf-8
#添加引用
import requests
import pickle
#尝试导入先前账号密码
try :
ins=open('data.pkl','rb')
payload2=pickle.load(ins)
except:
#否则输入宽带账号密码
name=raw_input(u"输入账号")
password=raw_input(u"输入密码")
#设置更改宽带设置所需字典
payload2={
"cbid.network.wan.username":name,
"cbid.network.wan.password":password,
"cbid.network.wan.randommac":"1",
"cbid.network.wan.autoredial":"1",
"cbid.network.wan.dialtype":"3",
"cbid.network.wan.proto":"pppoe",
"cbid.network.wan.macaddr":"",
"step":"4",
"quit":"0",
}
#新建一个requests
session_requests=requests.session()
#指定访问url
login_url='http://192.168.1.1/cgi-bin/luci'
#设置登录所需字典
payload = {
"luci_username":"root",
"luci_password": "admin"
}
#POST操作登录
result=session_requests.post(login_url,data=payload)
#生成新的跳转url
new_url=result.url+"/admin/guide"
#POST操作修改宽带设置
result2=session_requests.post(new_url,data=payload2)
#打印结果提示页面
print result2.content
#存储账号密码
output = open('data.pkl', 'wb')
pickle.dump(payload2, output)
file.close(output)