98 lines
2.8 KiB
Python
Executable File
98 lines
2.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
Shows the signal quality levels from the Hitron CVE30360 Cable modem
|
|
"""
|
|
|
|
import hashlib
|
|
import re
|
|
import requests
|
|
from bs4 import BeautifulSoup
|
|
from tabulate import tabulate
|
|
|
|
|
|
def login():
|
|
"""
|
|
Logins into the webserver, returns a cookie to be used in the requests
|
|
"""
|
|
payload = {
|
|
'active_page': 'page_login',
|
|
'md5_pass': '',
|
|
'auth_key': '',
|
|
'username': 'home',
|
|
}
|
|
|
|
req = requests.get('http://192.168.1.1/')
|
|
cookies = req.cookies
|
|
|
|
matches = re.search(r'<INPUT type=HIDDEN name="auth_key" value="(.+?)">',
|
|
req.text)
|
|
auth_key = matches[1]
|
|
md5 = hashlib.md5()
|
|
md5.update(('%s%s' % ('zonnet', auth_key)).encode('utf-8'))
|
|
hexdigest = md5.hexdigest()
|
|
|
|
payload['auth_key'] = auth_key
|
|
payload['md5_pass'] = hexdigest
|
|
|
|
req = requests.post('http://192.168.1.1/index.cgi', data=payload,
|
|
cookies=cookies)
|
|
return cookies
|
|
|
|
|
|
def page_equipment_status(cookies):
|
|
"""
|
|
Returns the equipment status data
|
|
"""
|
|
req = requests.get('http://192.168.1.1/' +
|
|
'index.cgi?active_page=page_equipment_status',
|
|
cookies=cookies)
|
|
|
|
soup = BeautifulSoup(req.text, 'html.parser')
|
|
tables = soup.find_all('table')
|
|
downstream = tables[60]
|
|
upstream = tables[61]
|
|
|
|
downtable = []
|
|
keys = ['rx_id_val_dn_', 'status_val_dn_', 'freq_val_dn_', 'power_val_dn_',
|
|
'snr_val_dn_']
|
|
for chan in range(0, 8):
|
|
row = []
|
|
for key in keys:
|
|
row.append(downstream.find("td", {"id": key + str(chan)}).
|
|
renderContents().strip().decode('utf-8').
|
|
replace(' MHz', '').replace(' dBmV', '').
|
|
replace(' dB', '')
|
|
)
|
|
downtable.append(row)
|
|
|
|
uptable = []
|
|
keys = ['rx_id_val_dn_', 'cannel_id_val_dn_', 'freq_val_dn_',
|
|
'power_val_dn_']
|
|
for chan in range(0, 2):
|
|
row = []
|
|
for key in keys:
|
|
row.append(upstream.find("td", {"id": key + str(chan)}).
|
|
renderContents().strip().decode('utf-8').
|
|
replace(' MHz', '').replace(' dBmV', '')
|
|
)
|
|
uptable.append(row)
|
|
|
|
return (downtable, uptable)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
COOKIE = login()
|
|
(DOWN, UP) = page_equipment_status(COOKIE)
|
|
|
|
print(" --- Canais Downstream ---")
|
|
HEADERS = ['ID Recetor', 'Estado', 'Frequência (MHz)', 'Potência (dBmV)',
|
|
'SNR (dB)']
|
|
print(tabulate(DOWN, headers=HEADERS))
|
|
|
|
print("\n --- Canais Upstream ---")
|
|
HEADERS = ['ID Recetor', 'Channel ID', 'Frequência (MHz)',
|
|
'Potência (dBmV)']
|
|
print(tabulate(UP, headers=HEADERS))
|