kbr / fritzconnection

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

Add url filtering configuration #206

Open serv-inc opened 5 months ago

serv-inc commented 5 months ago

Hi, thanks for this.

In case you're interested in enabling the internet blacklist, the following code does this (using the request api):

import requests
from typing import List

common_data = {"xhr": 1, "lang": "de", "page": "kids_blacklist"}

def get(mysid: str) -> List[str]:
    data = dict(common_data)
    data["sid"] = mysid
    data["xhrId"] = "all"
    result = requests.post("http://192.168.178.1/data.lua", data=data)
    return [x['url'] for x in result.json()['data']['list']]

def change(mysid: str, blacklist: List[str]) -> None:
    data = dict(common_data)
    data["listtype"] = "black"
    data["apply"] = "true"
    data["sid"] = mysid
    data["urllist"] = "\n".join(blacklist)
    requests.post("http://192.168.178.1/data.lua", data=data)

The sid was retrieved from

def get_sid(password: str) -> str:
    fc = FritzConnection(address="192.168.178.1", password=password)
    (_, sid) = list(fc.http_interface._get_sid())
    return sid

If you want to use this code, feel welcome. Licensed via MIT license. Or contact me if you need another one.