Created
January 21, 2023 15:06
-
-
Save killerbees19/d436e0811280e53edddefa12e635cbf6 to your computer and use it in GitHub Desktop.
Reverse DNS record check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# v1.0.0 (2023-01-21) cs@fnx.li | |
HOSTS=(foo.example.org bar.example.com) | |
SIMPLE=(host1 host2 host3) | |
SUFFIX=".example.net" | |
for simple in "${SIMPLE[@]}" | |
do | |
HOSTS+=("${simple}${SUFFIX}") | |
done | |
for host in "${HOSTS[@]}" | |
do | |
result=0 | |
for record in A AAAA | |
do | |
addrs=$(dig "$record" "$host" +short 2>/dev/null) | |
while IFS= read -r addr | |
do | |
[[ -z "$addr" ]] && continue | |
ptr=$(dig -x "$addr" +short 2>/dev/null | sed 's/\.$//g' | sort | uniq) | |
check=$(grep -F "$host" <<< "$ptr") | |
ptr=$(tr '\n' ' ' <<< "$ptr") | |
ptr=${ptr%% } | |
result=1 | |
[[ "$check" != "$host" ]] \ | |
&& echo "$host [$addr]: MISMATCH ($ptr)" >&2 \ | |
|| echo "$host [$addr]: OK ($ptr)" | |
done <<< "$addrs" | |
done | |
[[ "$result" -ne 1 ]] && echo "$host: MISSING A/AAAA RECORD!" >&2 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment