Code
#encoding =utf-8#author: walker#date: 2015-08-05#function: tp-link to switch Ip#memo by disconnecting the connection: This code has been python3.4 tested (for tl-wr847n) Import base64, requests, tracebackdef changeip (): ip = ' 192.168.1.1 ' user = ' admin ' pwd = ' admin ' desturl = ' http:/ /' + ip + '/userrpm/statusrpm.htm? Disconnect=%b6%cf%20%cf%df&wan=1 ' auth = ' basic ' + Base64.b64encode ((user+ ': ' +pwd). Encode (encoding= ' utf-8 ')). Decode (encoding= ' utf-8 ') heads = { ' Accept ': ' */* ', ' user-agent ': ' mozilla/4.0 (compatible; msie 8.0; windows nt 6.1; wow64; trident/4.0; slcc2; .net clr 2.0.50727; .net clr 3.5.30729; .net clr 3.0.30729; . net4.0c; . net4.0e) ', ' Referer ' : ' http//' + ip + '/userrpm/statusrpm.htm ', # ' Authorization ' : Auth ' Cookie ': ' authorization= ' + auth } try: r = requests.get (Url=desturl, headers=heads) print (r) except: exMsg = ' * exmsg:\n ' + Traceback.print_exc () print (exmsg) if __name__ == "__main__": changeip ()
Note
The authentication section cannot be copied completely, and the request header can be analyzed by the browser.
Reference:
1. Restart the Tp-link router with Python (restart)
2, Python login tp-link router for IP script (re-connected)
3, Python One-click Set router
Walker * * *
This article is from "Walker's Journal" blog, please be sure to keep this source http://walkerqt.blog.51cto.com/1310630/1681948
Python3 Switch tp-link External network IP