72 lines
1.8 KiB
Python
Executable File
72 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import hashlib
|
|
import re
|
|
from datetime import datetime
|
|
import time
|
|
import asyncio
|
|
import json
|
|
import requests
|
|
import websockets
|
|
|
|
payload = {
|
|
'active_page': 'page_login',
|
|
'md5_pass': '',
|
|
'auth_key': '',
|
|
'username': 'home',
|
|
}
|
|
|
|
r = requests.get('http://192.168.1.1/')
|
|
cookies = r.cookies
|
|
|
|
matches = re.search(r"<INPUT type=HIDDEN name=\"auth_key\" value=\"(.+?)\">", r.text)
|
|
auth_key = matches[1]
|
|
m = hashlib.md5()
|
|
m.update(('%s%s' % ('zonnet', auth_key)).encode('utf-8'))
|
|
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)
|
|
|
|
payload = {
|
|
'cable_settings': 1,
|
|
'active_page': 'page_cable_settings',
|
|
}
|
|
|
|
#fields = ['snr_val_dn', 'power_val_dn', 'power_val_up']
|
|
fields = ['snr_val_dn', 'power_val_dn']
|
|
|
|
async def down(websocket, path):
|
|
while True:
|
|
ts = datetime.now()
|
|
|
|
result = {'ts': ts.strftime('%Y-%m-%d %H:%M:%S'), 'channels': []}
|
|
|
|
r = requests.post('http://192.168.1.1/index.cgi?rand=' + str(int(ts.strftime("%s"))), data=payload, cookies=cookies)
|
|
matches = re.finditer(r"change_field_if_exist\('(.+?)_(\d)', '(.+?)'\);", r.text)
|
|
|
|
for m in matches:
|
|
if m.group(1) in fields:
|
|
try:
|
|
curr = result['channels'][int(m.group(2))]
|
|
except IndexError:
|
|
curr = {}
|
|
|
|
curr[m.group(1)] = float(m.group(3).replace(' dBmV', '').replace(' dB', ''))
|
|
|
|
try:
|
|
result['channels'][int(m.group(2))] = curr
|
|
except IndexError:
|
|
result['channels'].append(curr)
|
|
|
|
await websocket.send(json.dumps(result))
|
|
await asyncio.sleep(1)
|
|
|
|
|
|
start_server = websockets.serve(down, '192.168.1.4', 5678)
|
|
|
|
asyncio.get_event_loop().run_until_complete(start_server)
|
|
asyncio.get_event_loop().run_forever() |