Tags:
scripts
Test forward and reverse DNS with bash script
#!/bin/bash
TEST=$1
if [[ "${TEST:0-1}" != '.' ]];then
TEST=$TEST. ## add dot
fi
IPS=$(dig ${TEST} a ${TEST} aaaa +short)
echo IPS: $IPS
if [[ $IPS == "" ]]; then
echo No IPs
exit -1
fi
while IFS= read -r ipline
do
RESULT=$(dig -x $ipline +short)
if [[ "$RESULT" == "$TEST" ]]; then
echo Success Forward/Reverse
echo " " $TEST =\>
echo " " $ipline =\>
echo " " $RESULT
else
echo FAILED FORWARD/REVERSE
echo " " $TEST =\>
echo " " $ipline =\>
echo " " $RESULT
fi
done < <(printf '%s\n' "$IPS")
$ ./script.sh dns.google
IPS: 8.8.4.4 8.8.8.8 2001:4860:4860::8888 2001:4860:4860::8844
Success Forward/Reverse
dns.google. =>
8.8.4.4 =>
dns.google.
Success Forward/Reverse
dns.google. =>
8.8.8.8 =>
dns.google.
Success Forward/Reverse
dns.google. =>
2001:4860:4860::8888 =>
dns.google.
Success Forward/Reverse
dns.google. =>
2001:4860:4860::8844 =>
dns.google.