Skip to content

Instantly share code, notes, and snippets.

@gorillamoe
Created December 23, 2017 20:10
Show Gist options
  • Save gorillamoe/f286a4e9b57c56c77136e1ec22fb7d48 to your computer and use it in GitHub Desktop.
Save gorillamoe/f286a4e9b57c56c77136e1ec22fb7d48 to your computer and use it in GitHub Desktop.
Reboot/Restart Telekom Speedport
#!/bin/bash
# Usage:
# ./reboot-telekom-speedport.bash "URL or IP of speedport" "password of speedport"
# Example:
# ./reboot-telekom-speedport.bash "http://192.168.2.1" "aBcDEf1337GHijk"
main() {
local speedport
local devpwd
local challenge
local hashpwd
speedport="$1"
devpwd="$2"
# Get the challenge value
challenge=$(wget -q -O - "${speedport}/data/Login.json?_time=1511719881983&_rand=666&csrf_token=sercomm_csrf_token" | sed 's/.*challenge", "varvalue"\: "\([^"]*\).*/\1/')
# Hashed password + challenge
hashpwd=$(echo -n "${devpwd}${challenge}" | sha256sum | cut -d" " -f1)
# Log in to the server
wget -q \
--save-cookies cookies.txt \
--keep-session-cookies \
--post-data "password=${hashpwd}&showpw=0&csrf_token=sercomm_csrf_token" \
--delete-after \
"${speedport}/data/Login.json?lang=en"
# Extract CSRF Token
csrftoken=$(wget --load-cookies cookies.txt -q -O - "${speedport}/html/content/overview/index.html?lang=en" | grep "var csrf_token " | cut -d "'" -f 2)
# Reboot!
wget -q \
--load-cookies cookies.txt \
--post-data "reboot_device=true&csrf_token=${csrftoken}" \
--delete-after \
"${speedport}/data/Reboot.json?_time=1511727315027&_rand=128&csrf_token=${csrftoken}&lang=en"
# Cleaning up
rm cookies.txt
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment