commit 37825d9db59c7266dc73466b33958be085788221 Author: Sándor Date: Fri Feb 23 19:56:21 2024 +0100 Add check_dnsbl.sh diff --git a/check_dnsbl.sh b/check_dnsbl.sh new file mode 100644 index 0000000..e4477ac --- /dev/null +++ b/check_dnsbl.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Test if any IP4 and IP6 addresses of a hostname blocked on a DNSBL +# 2024-02-23 +# by Sandros + +# Parameter check +if [[ $# -ne 2 ]]; then + echo "Usage: ./${0##*/} " + exit 1 +fi + +# Get IPs +IPS=$(dig +short $1 A | sort -u) +IP6S=$(dig +short $1 AAAA | sort -u) + +IPSP="" + +# Prepare IP4 addresses +if [ ! -z "$IPS" ]; then + for IP in $IPS; do + # Check IP format + if [[ ! ${IP##*[[:space:]]} =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + # skip if invalid + continue + fi + + # Reverse IP octet order + IPSP="$IPSP $(sed -r 's/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/\4.\3.\2.\1/' <<< ${IP##*[[:space:]]})." + done +fi + +# Prepare IP6 addresses +if [ ! -z "$IP6S" ]; then + for IP6 in $IP6S; do + IPSP="$IPSP $(sipcalc $IP6 | fgrep Expanded | cut -d '-' -f 2 | sed 's/://g' | rev | sed 's/[0-9a-f]/&./g')" + done +fi + +# Loop through IPs +listed=0 +for IP in $IPSP; do + # Performs the actual lookup against blacklists + if host -W 2 -t a $IP$2 >/dev/null 2>&1; then + ((listed++)) + fi +done + +echo $listed +exit 0 \ No newline at end of file