Created
July 6, 2018 08:53
-
-
Save nielsvr/c20b72ca31ce904a32994fab57770e31 to your computer and use it in GitHub Desktop.
Matches a list of domains A-record against an expected IP
This file contains hidden or 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 | |
# 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