Last active
April 3, 2020 13:30
-
-
Save ni554n/fdbab004af3b5c6b28b961af96347250 to your computer and use it in GitHub Desktop.
A Python 3 script to reboot TP-LINK TD-W8950N / TD-W8950ND routers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
A python 3 script to reboot TP-LINK routers. | |
Tested on: TD-W8950N / TD-W8950ND. | |
Author: Nissan Ahmed | |
""" | |
import base64 | |
from http.client import HTTPConnection | |
# Change default router IP if needed. | |
ip = '192.168.1.1' | |
# Update username:password if changed. | |
auth = 'admin:admin' | |
Conn = HTTPConnection(ip) | |
auth = base64.b64encode(auth.encode()).decode('ascii') | |
headers = { | |
'referer': 'http://' + ip, | |
'cookie': 'Authorization=Basic ' + auth | |
} | |
try: | |
Conn.request('GET', '/wancfg.cmd?action=view', headers=headers) | |
except Exception: | |
print('Failed to connect. Check if IP / auth is valid.') | |
exit() | |
body = str(Conn.getresponse().read()) | |
start = body.find('var sessionKey') | |
end = body.find(';', start) | |
if start != -1: | |
key = body[start + 19: end - 2] | |
print('Rebooting...') | |
Conn.request('GET', '/rebootinfo.cgi?sessionKey=' + key, headers=headers) | |
else: | |
print('Failed to reboot!') | |
Conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment