Created
June 13, 2016 15:19
-
-
Save FGFW/93baba31dcfa814ac551ba010ddebdb3 to your computer and use it in GitHub Desktop.
python3登录极路由并读取宽带帐号帐号密码.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
python3登录极路由并读取宽带帐号帐号密码.py | |
2016年6月13日 11:15:21 codegay | |
之前写过python3重启极路由的程序,这次写一下读取宽带帐号密码。 | |
也很简单,纯粹是重复练习。 | |
""" | |
import re | |
import requests | |
data={'username':'admin', | |
'password':'123456' | |
} | |
#如果post的数据为一个字典对象, | |
#http头会自动设置为Content-Type: application/x-www-form-urlencoded | |
#登录 | |
url="http://192.168.199.1/cgi-bin/turbo/admin_web" | |
session=requests.Session() | |
txt=session.post(url,data=data,).text #登录并取网页内容 | |
stok=re.findall(''';stok=(\w+)''',txt)[0] #提取stok | |
print("取到的stok:",stok,"\n\n\n") | |
#读取读取wan口配置信息(其中包含有宽带帐号密码) | |
apiurl='http://192.168.199.1/cgi-bin/turbo//;stok={}/api/openapi_proxy/call'.format(stok) | |
txt=session.post(apiurl,data='''{"method":"network.wan.get_wan_config","data":{}}''') | |
waninfo=txt.json() | |
print('wan口配置信息:',waninfo,"\n\n\n") | |
#成功请求后会返回一个json数据,requests会自动转成python字典对象 | |
#提取信息很方便 | |
print("宽带用户名:",waninfo['data']['inactive_config']['pppoe']['username']) | |
print("密码:",waninfo['data']['inactive_config']['pppoe']['password']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment