Skip to content

Instantly share code, notes, and snippets.

@fabsrc
Last active November 4, 2021 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fabsrc/9948deefdac57a2fe3e2c9dc15b73028 to your computer and use it in GitHub Desktop.
Save fabsrc/9948deefdac57a2fe3e2c9dc15b73028 to your computer and use it in GitHub Desktop.
Check internet connection and restart Technicolor TC7200 router
#! /bin/bash
IP="192.168.0.1"
USERNAME=
PASSWORD="admin"
FAILURE_THRESHOLD=10
SLEEP_TIME=5
function restart {
CREDENTIALS="$(printf "$USERNAME:$PASSWORD" | base64)"
CSRF=$(curl http://$IP/RgSecurity.asp --header "Authorization: Basic $CREDENTIALS" | grep CSRFValue | sed -e 's/.*value=\(.*\)>/\1/')
curl "http://$IP/goform/RgSecurity" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Authorization: Basic $CREDENTIALS" \
--data "CSRFValue=$CSRF&HttpUserId=&Password=&PasswordReEnter=&RestoreConfirmPop=0&RestoreFactoryNo=0x00&mCmReset=1"
}
FAILED_CHECKS=0
function check {
if [ $FAILED_CHECKS -ge $FAILURE_THRESHOLD ]; then
echo "Restarting router now..."
restart
elif [ $(wget -q --spider --tries=3 --timeout=2 http://google.com) $? -eq 0 ]; then
echo "All fine"
exit 0
else
echo "No internet connection..."
if [ $(ping -q -c 1 -W 1 $IP >/dev/null) $? -eq 0 ]; then
echo "Router is up..."
FAILED_CHECKS=$((FAILED_CHECKS+1))
echo "Fail #$FAILED_CHECKS"
sleep $SLEEP_TIME
check
else
echo "Router is down"
exit 0
fi
fi
}
check
*/5 * * * * flock -n /tmp/checkAndRestartRouter.lock ~/scripts/checkAndRestartRouter.sh &>/dev/null
@gsustek
Copy link

gsustek commented Mar 15, 2020

Does not work any more:-)
`* upload completely sent off: 110 out of 110 bytes

  • HTTP 1.0, assume close after body
    < HTTP/1.0 302 Redirect
    < Server: PS HTTP Server
    < Location: http://192.168.0.1/login.asp
    < Content-type: text/html
    < Connection: close`

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