kbr / fritzconnection

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

How to remove an inactive host from FritzBox #83

Closed Kampi closed 3 years ago

Kampi commented 3 years ago

I use the following example script to list all hosts from my FritzBox:

from fritzconnection.lib.fritzhosts import FritzHosts

fh = FritzHosts(address = "192.168.178.1", password = "")
hosts = fh.get_hosts_info()
for index, host in enumerate(hosts, start=1):
    status = 'active' if host['status'] else  '-'
    ip = host['ip'] if host['ip'] else '-'
    mac = host['mac'] if host['mac'] else '-'
    hn = host['name']
    print(f'{index:>3}: {ip:<16} {hn:<28} {mac:<17}   {status}')

Can I use fritzconnection to remove all inactive hosts from the FritzBox? And what is the best way to do it?

kbr commented 3 years ago

I don't know whether this can be done or not. At least in the FritzBox admin backend there is an option to delete idle connections. But for me it is unclear if this is just a removement from the overview. The latter is easy to achieve by filtering the hosts:

active_hosts = [host for host in hosts if host['status']]

Basically with fritzconnection you can execute every action provided by the TR-064 protokoll as documented by AVM: https://avm.de/service/schnittstellen/

If you find a corresponding action to delete idle connections please let me know. May be we can add it as a shortcut to the FritzHosts library module.