Files
random_scripts/check_ptr.sh

27 lines
558 B
Bash
Raw Normal View History

2024-02-23 20:17:08 +01:00
#!/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 1 ]]; then
echo "Usage: ./${0##*/} <hostname>"
exit 1
fi
# Get IPs
IPS="$(dig +short $1 A | sort -u) $(dig +short $1 AAAA | sort -u)"
# Loop through IPs
2024-02-23 20:29:05 +01:00
fails=0
2024-02-23 20:17:08 +01:00
for IP in $IPS; do
# Performs the actual lookup against blacklists
RESULT=$(host $IP | rev | cut -d" " -f1 | rev | sed 's/.$//')
if [ "$RESULT" != "$1" ]; then
2024-02-23 20:29:05 +01:00
((fails++))
2024-02-23 20:17:08 +01:00
fi
done
2024-02-23 20:29:05 +01:00
echo $fails
2024-02-23 20:17:08 +01:00
exit 0