Skip to content

Instantly share code, notes, and snippets.



Last active Nov 2, 2017
What would you like to do?
Checks if the input is looks like an IP address
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;
return "$INVALID"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment