Skip to content

Instantly share code, notes, and snippets.

@Xinayder
Last active December 27, 2016 21:52
Show Gist options
  • Save Xinayder/a61e844d13456735e9d4781aed2546c0 to your computer and use it in GitHub Desktop.
Save Xinayder/a61e844d13456735e9d4781aed2546c0 to your computer and use it in GitHub Desktop.
#!/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