Last active
December 14, 2023 16:30
-
-
Save pjvds/b88f51a3d5f6e5f0718a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script resets the AVM FritzBox router | |
# | |
# The procedure is as follow: | |
# 1. GET request logincheck.lua | |
# 2. grep the session id from the location header | |
# 3. POST request reboot.lua with session id | |
# 4. grep the potentialy new session id from the location header | |
# 5. GET request on reboot.lua with session id | |
echo "looking for fritz.box" | |
if ! ping -c1 fritz.box &>/dev/null; then | |
echo "couldn't find fritz.box" | |
exit | |
fi | |
echo "fritz.box found" | |
echo "retrieving session id $SID" | |
SID=$(curl -s -I "http://fritz.box/logincheck.lua" | grep -Fi Location | awk -F'[=]' '{print $2}') | |
SLEEP 1 | |
echo "session id $SID" | |
echo "requesting reboot" | |
SID=$(curl -s -i -H "Content-Type: application/x-www-form-urlencoded" -H "Origin: http://fritz.box" -H "Referer: http://fritz.box/system/reboot.lua\?sid\=$SID" --data "reboot=&sid=$SID" -L http://fritz.box/system/reboot.lua | grep -Fi Location | awk -F'[=]' '{print $2}') | |
echo "new session id $SID" | |
SLEEP 1 | |
echo "requesting status" | |
curl http://fritz.box/reboot.lua?ajax=1&sid=$REBOOT_SID | |
SLEEP 1 | |
echo "waiting for fritzbox to go down" | |
while ping -c1 www.google.com &>/dev/null; do : sleep 1; done | |
echo "FRITZ!Box down" | |
SLEEP 1 | |
echo "waiting for fritzbox to come up" | |
while ! ping -c1 www.google.com &>/dev/null; do : sleep 1; done | |
echo "FRITZ!Box up" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Bergerie you need to replace 'SLEEP' with 'sleep'.
However this script still doesn't work for me.
looking for fritz.box fritz.box found retrieving session id session id requesting reboot new session id requesting status {"pid":"logout"}waiting for fritzbox to go down
then it waits there forever. I'm guessing the fritzbox isn't eben being told to restart, so he keeps silently pinging google until the internet goes down - which never happens.
How is this script even supposed to restart the router without any authentication?