Last active
September 5, 2018 19:29
-
-
Save lawrencegripper/58eaa1dd8ed858557b3165382e9306bb to your computer and use it in GitHub Desktop.
DNS check - Check DNS entry matches your public ip
This file contains 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/sh | |
set -e | |
export DNS_NAME=$1 | |
IP="NOTSET" | |
DNS_IP=$(nslookup $DNS_NAME 8.8.8.8 | awk -F': ' 'NR==5 { print $2 } ') | |
echo "Checking DNS - IP: $IP DNS_IP: $DNS_IP DNS_NAME: $DNS_NAME" | |
ATTEMPTS=25 | |
I=0 | |
while [ "$IP" != "$DNS_IP" ] && [ $I -lt $ATTEMPTS ] | |
do | |
DNS_IP=$(nslookup $DNS_NAME 8.8.8.8 | awk -F': ' 'NR==5 { print $2 } ') | |
IP=$(curl -s whatismyip.akamai.com) | |
echo "DNS_IP: $DNS_IP" | |
echo "EXTERNAL_IP: $IP" | |
sleep 10 | |
I=$(( $I + 1 )) | |
done | |
if [ "$IP" != "$DNS_IP" ] | |
then | |
echo "DNS not pointing to our location: FAILED!" | |
sleep 10 | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment