Last active
December 27, 2016 21:52
-
-
Save Xinayder/a61e844d13456735e9d4781aed2546c0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
MODEM_IP="192.168.1.1" | |
ROUTER_IP="192.168.0.1" | |
INTERFACE="eth0" | |
# Check if we are running the script as root | |
if [[ $(id -u) -ne 0 ]]; then | |
echo "Please execute this script as root." | |
exit 1 | |
fi | |
# Ping router 5 times to check if it's up; then ping modem 5 times to check if it's up. | |
# If any of these "tests" fail, we restart the interface. | |
if [[ ! $(ping -c 5 $ROUTER_IP 2>&1 /dev/null | echo $?) -eq 0 ]] && [[ ! $(ping -c 5 $MODEM_IP 2>&1 /dev/null | echo $?) -eq 0 ]]; then | |
ifconfig $INTERFACE down | |
ifconfig $INTERFACE up | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment