【问题标题】:Using FritzConnection to change WIFI password使用 FritzConnection 更改 WIFI 密码
【发布时间】:2021-02-12 18:55:15
【问题描述】:

我想在我的 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)

这段代码 sn-p 关闭和打开 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

据我了解,我服务于该界面。

关于我在这里做错了什么有什么想法吗?

【问题讨论】:

  • 你走得更远了吗? 'WLANConfiguration:3''WLANConfiguration3' 似乎作为参数工作。
  • arguments=NewEnable=1call_action() 中不起作用,但arguments={NewEnable:1} 可以,所以请使用dict

标签: python-3.x raspberry-pi fritzbox


【解决方案1】:

FritzConnction 存在缺陷。可以在这里找到解决方案:

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

本质是FritzConnection的模板太多 s: 前缀。特别是 s:NewWEPKey0s:NewWEPKey1s:NewWEPKey2s:NewWEPKey3s:NewPreSharedKeys:NewKeyPassphrase。从正文中删除s: 就可以了。

我做了以下肮脏的黑客攻击来验证这篇论文: 在soaper.py我在第226行下面添加了(这是在方法execute()中,下面的代码sn-p:

    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)

在这种情况下,这会从那个身体中删除s:。这工作正常,密码被更改。

所以我的脚本如下所示:

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)

【讨论】:

    猜你喜欢
    • 2015-12-01
    • 1970-01-01
    • 2019-02-10
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 2014-12-10
    • 1970-01-01
    相关资源
    最近更新 更多