Skip to content

Instantly share code, notes, and snippets.

@KawaiDesu
Last active November 2, 2017 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KawaiDesu/afbf25a8ad3cfbe04706a46e2b7f5557 to your computer and use it in GitHub Desktop.
Save KawaiDesu/afbf25a8ad3cfbe04706a46e2b7f5557 to your computer and use it in GitHub Desktop.
Checks if the input is looks like an IP address
#!/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