Skip to content

Instantly share code, notes, and snippets.

@kindlehl
Created February 19, 2019 01:26
Show Gist options
  • Save kindlehl/cffa45765d32c5504e36f553cfa69ac7 to your computer and use it in GitHub Desktop.
Save kindlehl/cffa45765d32c5504e36f553cfa69ac7 to your computer and use it in GitHub Desktop.
Script to check zones. PUT THIS IN THE SCRIPTS FOLDER TO RUN SUCCESSFULLY
#!/bin/bash
if [ -z $1 ] || [ -z $2 ]; then
echo Hey you, use proper syntax!
echo 'checkzone.sh <zone name> <path/to/zonefile>'
echo Example: ./checkzone.sh 0.1.0.3.0.8.c.b.5.0.6.2.ip6.arpa db.0.1.0.3.0.8.c.b.5.0.6.2.ip6.arpa
exit 1
fi
expandIP() {
for IP in $@; do
sipcalc $IP | grep Expanded | awk '{print $4}'
done
}
/usr/sbin/named-compilezone -o- $1 $2 | grep PTR | awk '{print $1, $5}' > records$$
while read reverse hostname; do
# echo $reverse $hostname
echo Checking ${hostname}...
shortIP=$(dig +short AAAA $hostname)
fullIP=$(expandIP $shortIP)
if [[ -z $shortIP ]]; then
echo could not resolve $hostname to an IP address >&2
continue
fi
hostname2=$(dig +short -x $fullIP)
if ! [ "$hostname2" = "$hostname" ]; then
echo ERROR WITH HOST $hostname
echo " $hostname" resolves to "$fullIP"
echo " $fullIP" reverse resolves to "$hostname2"
echo " $($(dirname $0)/reverse2ip $reverse)" currently points to $hostname
fi
echo
done < records$$
rm records$$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment