Skip to content

Instantly share code, notes, and snippets.

@KawaiDesu

KawaiDesu/valid_ip.sh

Last active Nov 2, 2017
Embed
What would you like to do?
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