Created
December 29, 2018 18:08
-
-
Save Fusion86/2b5b8a51df791c55b3fa5420285e40d3 to your computer and use it in GitHub Desktop.
Restart shitty routers
This file contains hidden or 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
import re | |
import requests | |
import sys | |
config = { | |
"admin_page": "http://192.168.0.254", | |
"admin_username": "Admin", | |
"admin_password": "password", | |
} | |
def _get_url(url: str): | |
""" | |
Get full url to path. Url must include leading slash | |
""" | |
base_url = config["admin_page"] | |
if base_url.endswith("/"): | |
base_url = base_url.rstrip("/") | |
return base_url + url | |
def get_token() -> str: | |
""" | |
Get httoken | |
Returns token or None | |
""" | |
# If not logged in you'll be redirected to login.stm, which also has a `var _httoken = 'xxx';` in the page source | |
r = requests.get(_get_url("/status_main.stm")) | |
match = re.search(r"_httoken\s*=\s*['\"](.*)['\"]", r.text) | |
if match is None: | |
return None | |
else: | |
return match.group(1) | |
def login(token: str) -> bool: | |
""" | |
Login to admin page | |
Returns true on success | |
""" | |
data = { | |
"httoken": token, | |
"user": config["admin_username"], | |
"pws": config["admin_password"], | |
} | |
r = requests.post(_get_url("/cgi-bin/login.exe"), data=data) | |
# If the username/password is wrong you'll get redirected to login.stm | |
# If logged in successfully then you'll be redirected to index.stm | |
logged_in = "login.stm" not in r.url | |
return logged_in | |
def restart_router(token: str) -> bool: | |
""" | |
Restart router | |
Returns true on success | |
""" | |
data = {"httoken": token, "page": "tools_gateway", "logout": ""} | |
r = requests.post(_get_url("/cgi-bin/restart.exe"), data=data) | |
success = "wait.stm" in r.url | |
return True | |
if __name__ == "__main__": | |
print("==== Restart Arcadyan-like routers ====") | |
print("Retrieving token...") | |
token = get_token() | |
if not token: | |
sys.exit("Couldn't get token") | |
print("Logging in") | |
logged_in = login(token) | |
if not logged_in: | |
sys.exit("Couldn't login") | |
print("Trying to restart router... ", end="") | |
restarted = restart_router(token) | |
if restart_router: | |
print("Restarted router") | |
sys.exit(0) | |
else: | |
print("Couldn't restart router") | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment