Last active
January 6, 2017 01:12
-
-
Save SkypLabs/8758fa2aa63201b028d0ac680b2a90c4 to your computer and use it in GitHub Desktop.
Bash function for testing an IPv4 address
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
is_ipv4() { | |
local -r regex='^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' | |
[[ $1 =~ $regex ]] | |
return $? | |
} |
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
is_ipv4 $ip | |
if [ "$?" -ne 0 ] | |
then | |
echo "[x] $ip is not an IPv4" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment