Created
March 6, 2014 09:45
-
-
Save MartinDelille/9386306 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
# `pg` with no arguments ping the IP 8.8.8.8 (usefull for basic internet connection test), | |
# otherwise ping the given IP. If the IP is incomplete, it is concat with the default | |
# prefix 192.168.1 allowing easy local ping (eg ping 3.12 => 192.168.3.12) | |
function pg() { | |
ip4regex='^[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+$' | |
ip3regex='^[0-9]+[.][0-9]+[.][0-9]+$' | |
ip2regex='^[0-9]+[.][0-9]+$' | |
ip1regex='^[0-9]+$' | |
host=$@ | |
if [[ $# == 0 ]]; then | |
host="8.8.8.8" | |
elif [[ $@ =~ $ip4regex ]]; then | |
host="$@" | |
elif [[ $@ =~ $ip3regex ]]; then | |
host="192.$@" | |
elif [[ $@ =~ $ip2regex ]]; then | |
host="192.168.$@" | |
elif [[ $@ =~ $ip1regex ]]; then | |
host="192.168.1.$@" | |
fi | |
ping $host | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment