kbr / fritzconnection

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

`fritzconnection --reconnect` and `fritzstatus` seems to use a no longer existing service name #236

Open calestyo opened 3 days ago

calestyo commented 3 days ago

Hey.

At least on my 7590 AX with version 8.0 it says:

$ fritzconnection -e -u foo -p bar --reconnect

fritzconnection v1.14.0
FRITZ!Box 7590 AX at https://cerf
FRITZ!OS: 8.0

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/fritzconnection/core/fritzconnection.py", line 453, in call_action
    service = self.device_manager.services[service_name]
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'WANIPConn1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/fritzconnection", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/lib/python3/dist-packages/fritzconnection/cli/fritzinspection.py", line 167, in main
    execute()
  File "/usr/lib/python3/dist-packages/fritzconnection/cli/fritzinspection.py", line 162, in execute
    run_inspector(inspector, args)
  File "/usr/lib/python3/dist-packages/fritzconnection/cli/fritzinspection.py", line 150, in run_inspector
    inspector.fc.reconnect()
  File "/usr/lib/python3/dist-packages/fritzconnection/core/fritzconnection.py", line 507, in reconnect
    self.call_action("WANIPConn1", "ForceTermination")
  File "/usr/lib/python3/dist-packages/fritzconnection/core/fritzconnection.py", line 455, in call_action
    raise FritzServiceError(f'unknown service: "{service_name}"')
fritzconnection.core.exceptions.FritzServiceError: unknown service: "WANIPConn1"

There are however the following commands shown in introspection:

Service:            WANPPPConnection1
Action:             ForceTermination
Parameters:

    Name                                  direction     data type
...
Service:            WANIPConnection1
Action:             ForceTermination
Parameters:

    Name                                  direction     data type

So I guess WANIPConn1 was simply renamed to WANIPConnection1?


Similarly:

$ fritzstatus -e -u foo -p bar 

fritzconnection v1.14.0
FRITZ!Box 7590 AX at https://cerf
FRITZ!OS: 8.0

FritzStatus:

    is linked             : unsupported attribute "is_linked"
    is connected          : unsupported attribute "is_connected"
    external ip (v4)      : unsupported attribute "external_ip"
    external ip (v6)      : unsupported attribute "external_ipv6"
    internal ipv6-prefix  : unsupported attribute "ipv6_prefix"
    uptime                : unsupported attribute "str_uptime"
    bytes send            : unsupported attribute "bytes_sent"
    bytes received        : unsupported attribute "bytes_received"
    max. bit rate         : unsupported attribute "str_max_bit_rate"

Looking in the code, these seem to use WANIPConn (**note that here the code doesn't have the trailing 1 as above) but my FritzBox shows e.g. the following commands in introspection, e.g. for the external IP:

Service:            WANPPPConnection1
Action:             GetExternalIPAddress
Parameters:

    Name                                  direction     data type

    NewExternalIPAddress                     out ->     string
...
Service:            WANIPConnection1
Action:             GetExternalIPAddress
Parameters:

    Name                                  direction     data type

    NewExternalIPAddress                     out ->     string

So might be named differently in newer firmwares?

Thanks, Chris.

kbr commented 2 days ago

Way back in older OS versions there have been the two Services WANIPConn1 and WANIPConnection1 with partly overlapping functionality. So it could be that the description for WANIPConn1 has been silently removed in OS 8 by AVM. If this is the case there should be a fix, because this is a breaking change in FritzOS. This is not to hard, so hopefully I can care about it soon.

calestyo commented 1 day ago

Would a complete dump of fritzconnection -c help you?

It also seems that some of the properties might have changed. In some small Python test prog using the lib, I couldn’t find the external IPv6 address at all, and the IPv4 only in WANPPPConnection1 not WANIPConnection1.

calestyo commented 1 day ago
$ ptpython3
>>> import fritzconnection
>>> fc = fritzconnection.FritzConnection(address="foo",password="bar",user="baz")

I think currently in the code you use X_AVM_DE_GetExternalIPv6Address,... but that no longer seems to exist:

>>> fc.call_action(service_name="WANIPConnection1",action_name="X_AVM_DE_GetExternalIPv6Address")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/fritzconnection/core/fritzconnection.py", line 456, in call_action
    return self.soaper.execute(service, action_name, arguments)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/fritzconnection/core/soaper.py", line 286, in execute
    return handle_response(response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/fritzconnection/core/soaper.py", line 268, in handle_response
    raise_fritzconnection_error(response)
  File "/usr/lib/python3/dist-packages/fritzconnection/core/soaper.py", line 191, in raise_fritzconnection_error
    raise exception(message)
fritzconnection.core.exceptions.FritzActionError: UPnPError: 
errorCode: 401
errorDescription: Invalid Action

Neither that:

>>> fc.call_action(service_name="WANIPConnection1",action_name="GetExternalIPAddress")
{'NewExternalIPAddress': ''}

I found the external IPv4 in WANPPPConnection1:

>>> fc.call_action(service_name="WANPPPConnection1",action_name="GetInfo")
{'NewEnable': True, 'NewConnectionStatus': 'Connected', 'NewPossibleConnectionTypes': 'IP_Routed, IP_Bridged', 'NewConnectionType': 'IP_Routed', 'NewName': 'internet', 'NewUptime': 161144, 'NewUpstreamMaxBitRate': 36294339, 'NewDownstreamMaxBitRate': 29347045, 'NewLastConnectionError': 'ERROR_NONE', 'NewIdleDisconnectTime': 0, 'NewRSIPAvailable': False, 'NewUserName': 'foobar@setup.t-online.de', 'NewNATEnabled': True, 'NewExternalIPAddress': '1.2.3.4', 'NewDNSServers': '2003:180:2:7000::53, 2003:180:2:9000::53,217.237.151.115,217.237.148.102', 'NewMACAddress': '11:22:33:44:55:66', 'NewConnectionTrigger': 'AlwaysOn', 'NewLastAuthErrorInfo': '', 'NewMaxCharsUsername': 128, 'NewMinCharsUsername': 3, 'NewAllowedCharsUsername': '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-._@()#/%[]{}*+§$&=?!:;,', 'NewMaxCharsPassword': 64, 'NewMinCharsPassword': 3, 'NewAllowedCharsPassword': '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-._@()#/%[]{}*+§$&=?!:;,', 'NewTransportType': 'PPPoE', 'NewRouteProtocolRx': 'Off', 'NewPPPoEServiceName': '', 'NewRemoteIPAddress': '', 'NewPPPoEACName': 'MUNJ10', 'NewDNSEnabled': True, 'NewDNSOverrideAllowed': True}

But not in the counterpart in WANIPConnection1:

>>> fc.call_action(service_name="WANIPConnection1",action_name="GetInfo")
{'NewEnable': True, 'NewConnectionStatus': 'Connecting', 'NewPossibleConnectionTypes': 'IP_Routed, IP_Bridged', 'NewConnectionType': 'IP_Routed', 'NewName': 'mstv', 'NewUptime': 0, 'NewLastConnectionError': 'ERROR_NONE', 'NewRSIPAvailable': False, 'NewNATEnabled': True, 'NewExternalIPAddress': '', 'NewDNSServers': '0.0.0.0, 0.0.0.0', 'NewMACAddress': '11:22:33:99:88:77', 'NewConnectionTrigger': 'AlwaysOn', 'NewRouteProtocolRx': 'Off', 'NewDNSEnabled': True, 'NewDNSOverrideAllowed': False}