Last active
March 15, 2023 04:27
-
-
Save fliphess/a5cbdbf32d414b9e47bfd63c6e8c09d7 to your computer and use it in GitHub Desktop.
Reboot Arcadyan VGV7519 (Experia, Telfort NL) through the web interface using python
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
#!/usr/bin/env python | |
import getpass | |
import os | |
import re | |
import signal | |
import sys | |
from collections import namedtuple | |
from urllib import urlencode | |
from urllib2 import build_opener | |
def get_user_input(): | |
password = None | |
hostname = None | |
while not all((password, hostname)): | |
os.system('clear') | |
hostname = raw_input('\nPlease enter the hostname of the router --> ') | |
password = getpass.getpass('\nPlease enter the admin password of the router --> ') | |
output = namedtuple('config', 'hostname password') | |
return output(hostname=hostname, password=password) | |
def get_token_from_html(opener, url): | |
request_output = opener.open(url) | |
output = request_output.read() | |
token = re.findall(r"var._httoken.=.\'(.*?)\';", output, re.DOTALL) | |
if token: | |
return token[0] | |
return None | |
def login_on_router(opener, config): | |
url = 'http://{}/cgi-bin/login.exe'.format(config.hostname) | |
token = get_token_from_html(opener=opener, url=url) | |
data = { | |
"httoken": token, | |
"pws": config.password, | |
"user": "Admin" | |
} | |
return opener.open(url, urlencode(data)) | |
def reboot_router(): | |
config = get_user_input() | |
opener = build_opener() | |
login_on_router(opener=opener, config=config) | |
token_url = 'http://{}/system_r.stm'.format(config.hostname) | |
token = get_token_from_html(opener=opener, url=token_url) | |
url = 'http://{}/cgi-bin/restart.exe'.format(config.hostname) | |
data = { | |
"httoken": token, | |
"page": "tools_gateway", | |
"logout": None, | |
} | |
return opener.open(url, urlencode(data)) | |
def signal_handler(signal, frame): | |
print('\nExited because you pressed Ctrl+C!') | |
sys.exit(1) | |
if __name__ == "__main__": | |
signal.signal(signal.SIGINT, signal_handler) | |
reboot_router() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment