Closed jens-maus closed 8 years ago
The following URL should return a pretty nice parseable JSON output of the relevant data which we could then parse more easily than the current error prone HTML parsing routines:
http://fritz.box/query.lua?sid=<enter_your_sid_here>&network=landevice:settings/landevice/list(name,ip,mac,wlan,ethernet,active,online,guest)
Please note that the following shell script can be used to quickly parse the JSON output and which can be used in an adapted form to extract the necessary information more quickly/nicely than having to parse the HTML output of the FRITZ!Box:
#!/bin/bash
re1="\"(name)\"[[:space:]]*:[[:space:]]*\"([^\"]*)\""
re2="\"(mac)\"[[:space:]]*:[[:space:]]*\"([^\"]*)\""
re3="\"(active)\"[[:space:]]*:[[:space:]]*\"([^\"]*)\""
re4="\"(guest)\"[[:space:]]*:[[:space:]]*\"([^\"]*)\""
while read -r l; do
if [[ $l =~ $re1 ]] || [[ $l =~ $re2 ]] || [[ $l =~ $re3 ]] || [[ $l =~ $re4 ]]; then
name="${BASH_REMATCH[1]}"
value="${BASH_REMATCH[2]}"
echo "$name=$value"
fi
done
Implemented in v0.6
After some analysis it seems to be possible to directly query some status information from a fritz.box and get the result returned in JSON output:
Thus, hm_pdetect could be quite easily be changed to use this method instead of having to parse the HTML output. This would definitely be a better approach than the current implementation as it would