Skip to content

Instantly share code, notes, and snippets.

@nielsvr
Created July 6, 2018 08:53
Show Gist options
  • Save nielsvr/c20b72ca31ce904a32994fab57770e31 to your computer and use it in GitHub Desktop.
Save nielsvr/c20b72ca31ce904a32994fab57770e31 to your computer and use it in GitHub Desktop.
Matches a list of domains A-record against an expected IP
#!/bin/bash
# This script uses dig to retrieve the A record for domains
# Add your domains in a file called domains.txt, seperated by newlines
# Add your expected IP in a parameter -e=123.123.123.123
# Output is ok.txt with domains matching the IP, not-ok.txt with domains failing
# Parse parameters
for i in "$@"
do
case $i in
-e=*|--expecting=*)
EXPECTS="${i#*=}"
shift # past argument=value
;;
*)
# unknown option
;;
esac
done
echo "EXPECTING: $EXPECTS"
while read domain
do
# Get IP address defined in domain's root A-record
ipaddress=`dig $domain +short`
echo "Checking $domain"
if [ "$ipaddress" = "$EXPECTS" ]; then
echo -e "$domain OK" >> ok.txt
else
echo -e "$domain NOT OK: $ipaddress" >> not-ok.txt
fi
# Defines the text file from which to read domain names
done < domains.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment