diff options
Diffstat (limited to 'dnsbl-check.sh')
-rwxr-xr-x | dnsbl-check.sh | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/dnsbl-check.sh b/dnsbl-check.sh index f3632bd..9e202b6 100755 --- a/dnsbl-check.sh +++ b/dnsbl-check.sh @@ -25,6 +25,23 @@ export CRESET=$'\e[0m' export LIST=${LIST:-dnsbls.txt} +# is_ipv4: +# Checks if the provided string is a valid IPv4 address. +# +# @str String to check +# @return (stdout) 1 == valid ip, 0 == invalid ip +is_ipv4() { + local str="${1}" + local match + match=$(printf "${str}" | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$') + if [ "${match}" = "${str}" ]; then + printf 1 + return 0; + fi + printf 0; + return 1; +} + # main: # Ye olde' main. @@ -49,6 +66,11 @@ main() { dnsbls=($(grep -v '^#' "${LIST}")) fi + if [ $(is_ipv4 "${ip}") = 0 ]; then + printf "Provided IP '%s' is not a valid IPv4 address\n" "${ip}" + return 1 + fi + # If the terminal is not a char terminal (eg: someone is using less, more, # cat, etc), we don't want to print escape codes because they will get # mangled by the tool most likely. |