1

I'd like to change a the password of the guest WIFI on my FritzBox router. For connecting to the FritzBox I use the FritzConnection lib in Python. In general FritzConnection works: I am able to read information from the FritzBox and I am also able to enable or disable the guest WIFI. However, I am facing trouble in changing the password. I can read the password, though.

Here's what I've done so far:

#!/usr/bin/python3
from fritzconnection import FritzConnection
import pprint

pp = pprint.PrettyPrinter(indent=2)
fc=FritzConnection(address='192.168.2.1', password='XYZ', use_tls=True)

#switch guest WIFI off and on again - this works
state = fc.call_action('WLANConfiguration:3', 'GetInfo')
pp.pprint(state)
print("Disable WLAN")
fc.call_action('WLANConfiguration3',
               'SetEnable',
               arguments={'NewEnable':0})
state = fc.call_action('WLANConfiguration:3', 'GetInfo')
pp.pprint(state)
input("Press Enter to continue...")
print("Enable WLAN")
fc.call_action('WLANConfiguration3',
               'SetEnable',
               arguments=NewEnable=1)
state = fc.call_action('WLANConfiguration:3', 'GetInfo')
pp.pprint(state)

This code snippet switches the WIFI off and on, and this works fine. Please note that I used 2 different methods of parameter-passing for enabling and disabling. Both work.

Now, when it comes to changing the password I first read the security keys (which works) and then I try to set them anew (which does not work). For reading I do as follows:

securityKeys = fc.call_action('WLANConfiguration:3', 'GetSecurityKeys')
pp.pprint(securityKeys)

For writing first I tried:

fc.call_action('WLANConfiguration:3',
               'SetSecurityKeys',
               NewKeyPassphrase='BetterPassword')

this results in

fritzconnection.core.exceptions.FritzArgumentError: UPnPError:
errorCode: 402
errorDescription: Invalid Args

I also tried

fc.call_action('WLANConfiguration3',
               'SetSecurityKeys',
               arguments={'NewKeyPassphrase':'MeinPasswortIstBesser'})

and

fc.call_action('WLANConfiguration:3',
               'SetSecurityKeys',
               NewWEPKey0='',
               NewWEPKey1='',
               NewWEPKey2='',
               NewWEPKey3='',
               NewPreSharedKey='',
               NewKeyPassphrase="MeinPasswortIstBesser")

and

securityKeys['NewKeyPassphrase']='MeinPasswortIstBesser'
fc.call_action('WLANConfiguration3',
               'SetSecurityKeys',
               arguments=securityKeys)

but the result is always the same. Apparently I do something wrong with the parameters, however I cannot say, what it should be. Using the FritzConnection CLI tool tells me the interface:

fritzconnection --ip-address 192.168.2.1 -A 'WLANConfiguration3' 'SetSecurityKeys'

fritzconnection v1.3.4
FRITZ!Box 7590 at http://192.168.2.1
FRITZ!OS: 7.20


Service:            WLANConfiguration3
Action:             SetSecurityKeys
Parameters:

    Name                                  direction     data type

    NewWEPKey0                            -> in         string
    NewWEPKey1                            -> in         string
    NewWEPKey2                            -> in         string
    NewWEPKey3                            -> in         string
    NewPreSharedKey                       -> in         string
    NewKeyPassphrase                      -> in         string

and to my understanding I serve that interface.

Any ideas on what I am doing wrong here?

Solderdot
  • 11
  • 2
  • Did you go any further? It seems that `'WLANConfiguration:3'` and `'WLANConfiguration3'` work as parameters. – Timo Jun 06 '21 at 13:27
  • `arguments=NewEnable=1` is not working in `call_action()`, but `arguments={NewEnable:1}` does it, so use a `dict`. – Timo Jul 07 '21 at 12:01

1 Answers1

0

There is a flaw in FritzConnction. Solution can be found here:

https://github.com/kbr/fritzconnection/issues/66

The essence is that FritzConnection has a template with too many s: prefixes. In particular s:NewWEPKey0, s:NewWEPKey1, s:NewWEPKey2, s:NewWEPKey3, s:NewPreSharedKey and s:NewKeyPassphrase. Removing the s: from the body will do the trick.

I did the following dirty hack to verify this thesis: In soaper.py I added below line 226 (this is in the method execute(), the following code snippet:

    if 'NewKeyPassphrase' in body:
        print (body)
        print ('replacing......................................')
        body = body.replace('s:NewWEPKey0', 'NewWEPKey0')
        body = body.replace('s:NewWEPKey1', 'NewWEPKey1')
        body = body.replace('s:NewWEPKey2', 'NewWEPKey2')
        body = body.replace('s:NewWEPKey3', 'NewWEPKey3')
        body = body.replace('s:NewPreSharedKey', 'NewPreSharedKey')
        body = body.replace('s:NewKeyPassphrase', 'NewKeyPassphrase')
        print (body)

This removes the s: from that very body in that very case. This works fine, the password gets changed.

So my script looks like as follows:

from fritzconnection import FritzConnection
import pprint

pp = pprint.PrettyPrinter(indent=2)
fc=FritzConnection(address='192.168.2.1', user='FritzConnection', password='Dr3QL78ZYG58Nn98GVsx', use_tls=True)

securityKeys = fc.call_action('WLANConfiguration:3', 'GetSecurityKeys')
pp.pprint(securityKeys)

securityKeys['NewKeyPassphrase']='MeinPasswortIstUnfassbarGut'
pp.pprint(securityKeys)
fc.call_action('WLANConfiguration3',
               'SetSecurityKeys',
               arguments=securityKeys)

securityKeys = fc.call_action('WLANConfiguration:3', 'GetSecurityKeys')
pp.pprint(securityKeys)
Solderdot
  • 11
  • 2