Python3 control Router -- use requests to restart pole routing. py, python3.py

Source: Internet
Author: User

Python3 control Router -- use requests to restart pole routing. py, python3.py

This article describes how to use Python3 to control the vro -- use requests to restart the pole routing. py. The code is annotated and then written into a module that can be conveniently called.

Using fiddler to capture packets, you can see many HTTP headers. After trying to find that they are not all required.

'Upgrade-Insecure-requests': 1, # required item, value: 1

'Content-type': 'application/x-www-form-urlencoded', # required

Otherwise, the Set-Cookie returned by the response is not obtained.

"Python3 control vro -- use requests to restart the pole route. py May 10, 2016 06:20:56 codegay references requests documentation: http://cn.python-requests.org/zh_CN/latest/ "" import requestsimport reurl = "http: // 192.168.199.1/cgi-bin/turbo/admin_web "# capture packets with fiddler and check that many HTTP headers are not required. # 'Upgrade-Insecure-requests': 1, # required item, value: 1 # 'content-type': 'application/x-www-form-urlencoded ', # required items # Otherwise, Set-Cookiehead = {# '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.9 4 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 = your password", headers = head) txt = r. textstok = re. findall (''' stok = (\ w + ). +? Reboot ''', txt) [0] # stok will get a similar string # stok = '1f7a2b7034c67401a20d4ce0cdde7c7d 'print (stok) rooturl = 'HTTP: // 192.168.199.1/cgi-bin/turbo/'signed url = rooturl + '; stok = % s/api/system/reboot' % stok # with cookies after successful logon, find the stok and splice it into a URL get request to restart the route. # restart URL = 'HTTP: // 192.168.199.1/cgi-bin/turbo /; stok = 78e3516718ff32250fa796ed4462188c/api/system/reboot 'reboot = s. get (restart URL) # restart

The Python3 control router introduced in this article -- use requests to restart the pole route. the py knowledge has been introduced to you so much. The content of the Code in this article is accompanied by comments. If you have any questions during the reference process, please leave a message. The editor will reply to you in time, thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.