From cae8b920ffe8905a243e161d3ef1025aaa13f07a Mon Sep 17 00:00:00 2001 From: Marc Richter Date: Wed, 17 Feb 2021 10:49:47 +0100 Subject: [PATCH] Added support for Fritzbox Model 6490 Cable and potentially others, also requiring Login to extract traffic data. --- fritzbox_traffic.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/fritzbox_traffic.py b/fritzbox_traffic.py index 25ccb24..dbe41e3 100755 --- a/fritzbox_traffic.py +++ b/fritzbox_traffic.py @@ -20,11 +20,26 @@ import sys from fritzconnection import FritzConnection +def model_needs_login(model: str) -> bool: + models_require_login = [ + "FRITZ!Box 6490 Cable", + ] + for m in models_require_login: + if model.startswith(m): + return True + return False + + def print_values(): try: conn = FritzConnection(address=os.environ['fritzbox_ip']) + if model_needs_login(conn.modelname): + conn = FritzConnection(address=os.environ['fritzbox_ip'], + user='dslf-config', + password=os.environ['fritzbox_password'], + ) except Exception as e: - sys.exit("Couldn't get WAN traffic") + sys.exit("Couldn't establish connection to fritzbox") down_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetTotalBytesReceived')['NewTotalBytesReceived'] print('down.value %d' % down_traffic)