This article introduces Python3 control router-use requests to restart the pole route. py-related knowledge. The code is annotated accordingly, and then written into modules that can be conveniently called, if you are interested, let's take a look at this article to introduce Python3 control Router -- use requests to restart the pole route. py-related knowledge. The code is annotated accordingly and then written into modules 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 polar route. py May 10, 2016 06:20:56 codegay reference requests document: http://cn.python-requests.org/zh_CN/latest/ "" Import requestsimport reurl =" http://192.168.199.1/cgi-bin/turbo/ Admin_web "# Use fiddler to capture packets and you can see many HTTP headers. It is not necessary to try it. # '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.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 = 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 # take the cookies after successful logon and find the stok, after splicing a URL get request, you can restart the route once. # required 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, I would like to thank you for your support for the script home website!