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!