kbr / fritzconnection

Python-Tool to communicate with the AVM Fritz!Box by the TR-064 protocol and the AHA-HTTP-Interface
MIT License
304 stars 59 forks source link

Online Monitor #3

Closed TrevisGordan closed 4 years ago

TrevisGordan commented 4 years ago

["Maybe" unrelated to the overall project]

I just found (at least I think) by coincidence a awesome Goodie. With Fritzconection u can get the current Down-/Upstream to the ISP. But not the "Bandwidth Saturation" which would provide useful information. The Fritzbox has an "Online-Monitor" with a graph for that. I found that the browser makes a simple GET Req to a Url to retrieve that info and build the ajaxgraph every second.

Ok, turns out you need auth for the URL. You need to create a sid for the URL.

For me the URL looks like: "http://fritz.box/internet/inetstat_monitor.lua?sid=[YOUR-SID]&myXhr=1&action=get_graphic&useajax=1&xhr=1&t1569928285267=nocache"

Just go to the Online-Monitor page activate DevTools>Network and you will see the Packages coming in.

It should retrive Data simular to:

downstream: 106826000
ds_bps_curr: [17375, 105760, 5752, 73004, 9411, 2519, 4005, 2796, 2646, 8175, 4399, 4426, 2791, 4559, 3367, 2320,…]
ds_bps_curr_max: 105760
ds_bps_max: 13353250
ds_guest_bps_curr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
ds_mc_bps_curr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
dynamic: false
guest_us_bps: [0]
mode: "VDSL"
name: "sync_dsl"
upstream: 36680000
us_background_bps_curr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
us_bps_curr_max: 9914
us_bps_max: 4585000
us_default_bps_curr: [1468, 1048, 1249, 1182, 1321, 1296, 1253, 1405, 1642, 1207, 1206, 1538, 1452, 1009, 2106, 1315, 1491,…]
us_important_bps_curr: [1117, 272, 284, 134, 52, 88, 39, 28, 13, 84, 66, 56, 181, 57, 15, 15, 60, 93, 106, 136]
us_realtime_bps_curr: [658, 8594, 1914, 3741, 3962, 124, 632, 342, 119, 2607, 878, 475, 514, 3162, 578, 1650, 989, 122, 7,…]
_node: "sg0"

where the frist element of ds_bps_curr is the current Downstream viseversa to us_default_bps_curr for upstream.

I thought you might like that as well. Implementations for that are limitless. ;)

kbr commented 4 years ago

As you mentioned, this is unrelated to fritzconnection, which is TR-064 based.

As an example to get the "Bandwidth Saturation" please refer to the fritzstatus.py and fritzmonitor.py modules.

Please keep in mind that every web-scraping based solution may break with the next FritzOS release (projects working this way are unstable by design). The only reliable way to communicate with Fritz!Box routers is to use the official APIs published by the vendor: https://avm.de/service/schnittstellen/