Last active
November 2, 2017 07:40
-
-
Save KawaiDesu/afbf25a8ad3cfbe04706a46e2b7f5557 to your computer and use it in GitHub Desktop.
Checks if the input is looks like an IP 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
#!/bin/bash | |
valid_ip(){ # (ip) | |
local INVALID=0 | |
grep -Eq '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' <<< "$1" || INVALID=1 | |
for N in $(echo "$1" | tr '.' ' '); do | |
test "$N" -gt 255 && INVALID=1; | |
done | |
return "$INVALID" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment