Skip to content

Instantly share code, notes, and snippets.

@BigNerd
Created June 2, 2019 10:48
Show Gist options
  • Save BigNerd/b3d79fd1b40b5667a5663eaa5fa9e80f to your computer and use it in GitHub Desktop.
Save BigNerd/b3d79fd1b40b5667a5663eaa5fa9e80f to your computer and use it in GitHub Desktop.
This bash script downloads the current Fritz Box event log as JSON file and as TXT file
#!/bin/bash
#
# This bash script downloads the current Fritz Box event log as JSON file and as TXT file.
#
# The login procedure was implemented according to https://avm.de/fileadmin/user_upload/Global/Service/Schnittstellen/AVM_Technical_Note_-_Session_ID.pdf
#
# The script was tested successfully on MacOS High Sierra 10.13.6 with Fritz!Box 6490 Cable (kdg)
PASSWORD=<replace-with-your-fritz-box-password>
BASE_URL=http://fritz.box
CHALLENGE=$(curl ${BASE_URL}/login_sid.lua |grep -o -e "<Challenge>.*</Challenge>" |cut -d">" -f2 |cut -d"<" -f1)
MD5=$(echo -n ${CHALLENGE}-${PASSWORD} |iconv -t UTF-16LE |md5)
RESPONSE="${CHALLENGE}-${MD5}"
SID=$(curl -d "response=${RESPONSE}&lp=overview&username=" -H "Content-Type: application/x-www-form-urlencoded" POST ${BASE_URL}/index.lua |egrep -o -e "sid=[^&]+" |head -n 1 |cut -d"=" -f2)
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
OUTPUT_FILE=log-${TIMESTAMP}
OUTPUT_FILE_JSON=json/${OUTPUT_FILE}.json
OUTPUT_FILE_TXT=txt/${OUTPUT_FILE}.txt
mkdir -p json txt
curl -d "xhr=1&lang=de&page=log&sid=${SID}" -H "Content-Type: application/x-www-form-urlencoded" POST ${BASE_URL}/data.lua > ${OUTPUT_FILE_JSON}
cat ${OUTPUT_FILE_JSON} |jq '.data.log[] | .[0] + " " + .[1] + " " + .[2]' > ${OUTPUT_FILE_TXT}
cat ${OUTPUT_FILE_TXT}
echo ${OUTPUT_FILE_TXT}
@nospam2000
Copy link

I created a fork to get it running in my current environment (newer Fritz!Box, newer MacOS, using MacPorts)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment