我想在我的 FritzBox 路由器上更改访客 WIFI 的密码。为了连接到 FritzBox,我使用 Python 中的 FritzConnection 库。一般来说,FritzConnection 可以工作:我可以从 FritzBox 读取信息,也可以启用或禁用访客 WIFI。但是,我在更改密码时遇到了麻烦。不过,我可以读取密码。
这是我到目前为止所做的:
#!/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)
此代码段可关闭和打开 WIFI,效果很好。请注意,我使用了 2 种不同的参数传递方法来启用和禁用。两者都有效。
现在,在更改密码时,我首先读取安全密钥(有效),然后尝试重新设置它们(无效)。为了阅读,我执行以下操作:
securityKeys = fc.call_action('WLANConfiguration:3', 'GetSecurityKeys')
pp.pprint(securityKeys)
先写我试过:
fc.call_action('WLANConfiguration:3',
'SetSecurityKeys',
NewKeyPassphrase='BetterPassword')
这导致
fritzconnection.core.exceptions.FritzArgumentError: UPnPError:
errorCode: 402
errorDescription: Invalid Args
我也试过
fc.call_action('WLANConfiguration3',
'SetSecurityKeys',
arguments={'NewKeyPassphrase':'MeinPasswortIstBesser'})
和
fc.call_action('WLANConfiguration:3',
'SetSecurityKeys',
NewWEPKey0='',
NewWEPKey1='',
NewWEPKey2='',
NewWEPKey3='',
NewPreSharedKey='',
NewKeyPassphrase="MeinPasswortIstBesser")
和
securityKeys['NewKeyPassphrase']='MeinPasswortIstBesser'
fc.call_action('WLANConfiguration3',
'SetSecurityKeys',
arguments=securityKeys)
但结果总是一样的。显然我对参数做错了,但是我不能说它应该是什么。使用 FritzConnection CLI 工具告诉我界面:
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
据我了解,我服务于该界面。
关于我在这里做错了什么的任何想法?