Skip to content

Instantly share code, notes, and snippets.

@killerbees19
Created January 21, 2023 15:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killerbees19/d436e0811280e53edddefa12e635cbf6 to your computer and use it in GitHub Desktop.
Save killerbees19/d436e0811280e53edddefa12e635cbf6 to your computer and use it in GitHub Desktop.
Reverse DNS record check
#!/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