Created
November 3, 2023 15:06
-
-
Save KevinRohn/ce824f7388dbe48a2bff8a6d998be515 to your computer and use it in GitHub Desktop.
validate IPv4
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 | |
IP=$1 | |
result=`echo $IP | awk -F"\." ' $0 ~ /^([0-9]{1,3}\.){3}[0-9]{1,3}$/ && $1 <=255 && $2 <= 255 && $3 <= 255 && $4 <= 255 '` 2>/dev/null | |
if [ "$result" = "" ]; then | |
echo "IPv4 is invalid: $IP" | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment