update
This commit is contained in:
parent
6766067803
commit
d3c24b3362
|
@ -0,0 +1,97 @@
|
|||
#!/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))
|
30
monit.py
30
monit.py
|
@ -6,29 +6,13 @@ import re
|
|||
from datetime import datetime
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
#from tabulate import tabulate
|
||||
import mysql.connector
|
||||
|
||||
payload = {
|
||||
'active_page': 'page_login',
|
||||
'prev_page': '',
|
||||
'page_title': 'Login',
|
||||
'intercept_id': '-2',
|
||||
'no_dns': '0',
|
||||
'mimic_button_field': 'submit_button_login_submit%3A+..',
|
||||
'button_value': '',
|
||||
'strip_page_top': '0',
|
||||
'scroll_top': '0',
|
||||
'post_id': '0',
|
||||
'page_title_text': 'Login',
|
||||
'page_icon_number': '30',
|
||||
'defval_lang': '1',
|
||||
'defval_username': '',
|
||||
'md5_pass': '53c8a95730e66905d86b03ae7eec26b0',
|
||||
'auth_key': '1216289424',
|
||||
'lang=': '1',
|
||||
'md5_pass': '',
|
||||
'auth_key': '',
|
||||
'username': 'home',
|
||||
#'password_1636230399':''
|
||||
}
|
||||
|
||||
r = requests.get('http://192.168.1.1/')
|
||||
|
@ -43,9 +27,7 @@ hexdigest = m.hexdigest()
|
|||
payload['auth_key'] = auth_key
|
||||
payload['md5_pass'] = hexdigest
|
||||
|
||||
|
||||
r = requests.post('http://192.168.1.1/index.cgi', data=payload, cookies=cookies)
|
||||
#ts = time.time()
|
||||
ts = datetime.now()
|
||||
r = requests.get('http://192.168.1.1/index.cgi?active_page=page_equipment_status', cookies=cookies)
|
||||
|
||||
|
@ -54,7 +36,6 @@ tables = soup.find_all('table')
|
|||
downstream = tables[60]
|
||||
upstream = tables[61]
|
||||
|
||||
#print(" --- Canais Downstream ---")
|
||||
downtable = []
|
||||
keys = ['rx_id_val_dn_', 'status_val_dn_', 'freq_val_dn_', 'power_val_dn_', 'snr_val_dn_']
|
||||
for x in range(0, 8):
|
||||
|
@ -65,10 +46,6 @@ for x in range(0, 8):
|
|||
)
|
||||
downtable.append(row)
|
||||
|
||||
#headers = ['ID Recetor', 'Estado', 'Frequência (MHz)', 'Potência (dBmV)', 'SNR (dB)']
|
||||
#print(tabulate(downtable, headers=headers))
|
||||
|
||||
#print("\n --- Canais Upstream ---")
|
||||
uptable = []
|
||||
keys = ['rx_id_val_dn_', 'cannel_id_val_dn_', 'freq_val_dn_', 'power_val_dn_']
|
||||
for x in range(0, 2):
|
||||
|
@ -79,9 +56,6 @@ for x in range(0, 2):
|
|||
)
|
||||
uptable.append(row)
|
||||
|
||||
#headers = ['ID Recetor', 'Channel ID', 'Frequência (MHz)', 'Potência (dBmV)']
|
||||
#print(tabulate(uptable, headers=headers, tablefmt="psql"))
|
||||
|
||||
cnx = mysql.connector.connect(user='root', password='',
|
||||
host='127.0.0.1',
|
||||
database='monit')
|
||||
|
|
Loading…
Reference in New Issue