Created
July 9, 2013 19:42
-
-
Save n8felton/5960598 to your computer and use it in GitHub Desktop.
Check to see if you can ping the Gateway IP address, and if not, reset the interface.
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 | |
# Check to see if you can ping the Gateway IP address, and if not, reset the interface. | |
# Author: Nathan Felton | |
# Date: 2013-07-09 | |
if [ $EUID -ne 0 ]; then | |
echo "Run as root." | |
exit 1 | |
fi | |
GATEWAY=$(netstat -rn | grep "default" | awk '{print $2}') | |
if [[ $GATEWAY =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then | |
INTERFACE=$(netstat -rn | grep "default" | awk '{print $6}') | |
PING=$(ping -c 1 $GATEWAY) | |
if [ $? -eq 2 ]; then | |
echo "Gateway ping failed. Resetting $INTERFACE" | |
ifconfig $INTERFACE down | |
ifconfig $INTERFACE up | |
fi | |
else | |
echo "Network not active or is misconfigured." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment