Created
July 24, 2018 22:02
-
-
Save kugland/8bec53f964ecd92194d9995543066f7d to your computer and use it in GitHub Desktop.
Script para reiniciar o GVT PowerBox — SAGECOM FAST2764
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 python3 | |
import requests | |
import urllib3 | |
from html.parser import HTMLParser | |
ip = '192.168.25.1' | |
credentials = ('admin', 'gvt12345') | |
class SessionIdFinder(HTMLParser): | |
def handle_starttag(self, tag, attrs): | |
if tag == 'input': | |
attrs = dict(attrs) | |
if attrs['name'] == 'sessionid': | |
self.session_id = attrs['value'] | |
print('Trying to log into PowerBox ('+ip+')...') | |
try: | |
request = requests.get('http://'+ip+'/', auth=credentials, timeout=10) | |
except: | |
print('Error: unable to connect to PowerBox') | |
exit(1) | |
if request.status_code != 200: | |
print('Error: unable to log into PowerBox, status code =', request.status_code) | |
exit(1) | |
session_id_finder = SessionIdFinder() | |
session_id_finder.feed(request.text) | |
if not hasattr(session_id_finder, 'session_id'): | |
print('Error: unable to log into PowerBox') | |
exit(1) | |
print('Logged into PowerBox, session_id =', session_id_finder.session_id) | |
headers = { | |
'Referer': 'http://' + ip + '/index.cgi?page=resets&sessionid=' + session_id_finder.session_id, | |
'Origin': 'http://' + ip, | |
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/100.0 (KHTML, like Gecko) Chrome/50.0.0.0 Safari/100.0' | |
} | |
payload = { | |
'page': 'resets', | |
'sessionid': session_id_finder.session_id, | |
'action': 'submit', | |
'update': '0', | |
'factory_reset': 'reboot', | |
'factory_reboot': '' | |
} | |
try: | |
request = requests.post('http://'+ip+'/index.cgi', auth=credentials, | |
data=payload, headers=headers, timeout=10) | |
if request.status_code != 200: | |
raise "Failed" | |
print("Reboot command sent successfully") | |
except: | |
print("Unable to send reboot command") | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment