• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python3控制路由器——使用requests重启极路由.py

Python3控制路由器——使用requests重启极路由.py

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python3 requests,python3 requests安装,python3 requests.get,python3 requests库,python3 web.py等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

通过本文给大家介绍Python3控制路由器——使用requests重启极路由.py的相关知识,代码写了相应的注释,以后再写成可以方便调用的模块。

用fiddler抓包可以看到很多HTTP头,经过尝试发现不是都必须的。

'Upgrade-Insecure-Requests':1,#必要项,值为1

'Content-Type':'application/x-www-form-urlencoded',#必要项

否则取不到服务顺响应返回的Set-Cookie

"""
python3控制路由器--使用requests重启极路由.py
2016年5月10日 06:20:56 codegay
参考资料requests文档:
http://cn.python-requests.org/zh_CN/latest/
"""
import requests
import re
url="http://192.168.199.1/cgi-bin/turbo/admin_web"
#用fiddler抓包可以看到很多HTTP头,经过尝试发现不是都必须的。
#'Upgrade-Insecure-Requests':1,#必要项,值为1
#'Content-Type':'application/x-www-form-urlencoded',#必要项
#否则取不到服务顺响应返回的Set-Cookie
head={#'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Upgrade-Insecure-Requests':1,
'Content-Type':'application/x-www-form-urlencoded',
#'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36',
#'DNT':1,
#'Referer':'http://192.168.199.1/cgi-bin/turbo/admin_web'
}
s=requests.Session()
r=s.post(url,data="username=admin&password=你的密码",headers=head)
txt=r.text
stok=re.findall('''stok=(\w+).+?reboot''',txt)[0]
#stok会得到类似的字符串
#stok='1f7a2b7034c67401a20d4ce0cdde7c7d'
print(stok)
rooturl='http://192.168.199.1/cgi-bin/turbo/'
stokurl=rooturl + ';stok=%s/api/system/reboot' % stok
#带着成功登录后的cookies,并且找出stok,拼成下如URL get请求一次就可以完成路由的重启
#stokurl='http://192.168.199.1/cgi-bin/turbo/;stok=78e3516718ff32250fa796ed4462188c/api/system/reboot'
reboot=s.get(stokurl) #重启
</div>

关于本文给大家介绍的Python3控制路由器——使用requests重启极路由.py的知识就给大家介绍这么多,本文代码内容附有注释,大家在参考过程中有任何疑问欢迎给我留言,小编会及时回复大家的,在此也非常感谢大家对网站的支持!

</div>

您可能想查找下面的文章:

  • python中requests小技巧
  • Python的requests网络编程包使用教程
  • Python的requests网络编程包使用教程
  • Python3使用requests发闪存的方法
  • Python3控制路由器——使用requests重启极路由.py
  • Python3使用requests登录人人影视网站的方法
  • Python Requests安装与简单运用
  • Python3使用requests包抓取并保存网页源码的方法
  • Python3使用requests包抓取并保存网页源码的方法
  • python中requests模块的使用方法

相关文章

  • Python极简代码实现杨辉三角示例代码
  • Python的string模块中的Template类字符串模板用法
  • 详细解析Python当中的数据类型和变量
  • Python装饰器decorator用法实例
  • 用Python的urllib库提交WEB表单
  • python中redis的安装和使用
  • Python 类的继承实例详解
  • django通过ajax发起请求返回JSON格式数据的方法
  • 使用Python编写一个简单的tic-tac-toe游戏的教程
  • python 输出一个两行字符的变量

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python实现的二维码生成小软件
    • python使用线程封装的一个简单定时器类实例
    • 以一个投票程序的实例来讲解Python的Django框架使用
    • python通过pil模块将raw图片转换成png图片的方法
    • 深入解读Python解析XML的几种方式
    • python实现将html表格转换成CSV文件的方法
    • python备份文件以及mysql数据库的脚本代码
    • python Selenium爬取内容并存储至MySQL数据库的实现代码
    • python操作日期和时间的方法
    • python thread 并发且顺序运行示例

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有