Last active
November 4, 2021 18:49
-
-
Save fabsrc/9948deefdac57a2fe3e2c9dc15b73028 to your computer and use it in GitHub Desktop.
Check internet connection and restart Technicolor TC7200 router
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
#! /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 |
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
*/5 * * * * flock -n /tmp/checkAndRestartRouter.lock ~/scripts/checkAndRestartRouter.sh &>/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does not work any more:-)
`* upload completely sent off: 110 out of 110 bytes
< HTTP/1.0 302 Redirect
< Server: PS HTTP Server
< Location: http://192.168.0.1/login.asp
< Content-type: text/html
< Connection: close`