Last active
April 4, 2025 09:36
-
-
Save signalwerk/84b4f2643ec407a5ab8b215c05435c02 to your computer and use it in GitHub Desktop.
DNS Monitoring Script for Go-Live Moments
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 | |
# Replace these with your Pushover credentials | |
APP_TOKEN="your_app_token" | |
USER_KEY="your_user_key" | |
# Expected IP addresses | |
EXPECTED_IP_A="your_expected_ipv64_address" | |
EXPECTED_IP_AAAA="your_expected_ipv6_address" | |
# Domain to monitor | |
DOMAIN="your-domain.com" | |
# Log file path | |
LOG_FILE="dns_monitor.log" | |
# List of DNS servers to monitor | |
DNS_SERVERS=( | |
"dns1.your-domain.com" | |
"dns2.your-domain.com" | |
) | |
while true; do | |
TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S") | |
for DNS_SERVER in "${DNS_SERVERS[@]}"; do | |
# Check A record | |
IP_A=$(dig @$DNS_SERVER $DOMAIN A +short) | |
if [ "$IP_A" != "$EXPECTED_IP_A" ]; then | |
# Sound alarm and send Pushover notification | |
say "Changed" | |
curl -s \ | |
--form-string "token=$APP_TOKEN" \ | |
--form-string "user=$USER_KEY" \ | |
--form-string "message=A record at $DNS_SERVER for $DOMAIN changed to $IP_A" \ | |
https://api.pushover.net/1/messages.json | |
echo "$TIMESTAMP - A record at $DNS_SERVER for $DOMAIN changed to $IP_A" | tee -a "$LOG_FILE" | |
else | |
echo "$TIMESTAMP - no change for A record at $DNS_SERVER for $DOMAIN" | tee -a "$LOG_FILE" | |
fi | |
# Check AAAA record | |
IP_AAAA=$(dig @$DNS_SERVER $DOMAIN AAAA +short) | |
if [ -n "$IP_AAAA" ] && [ "$IP_AAAA" != "$EXPECTED_IP_AAAA" ]; then | |
# Sound alarm and send Pushover notification | |
say "Changed" | |
curl -s \ | |
--form-string "token=$APP_TOKEN" \ | |
--form-string "user=$USER_KEY" \ | |
--form-string "message=AAAA record at $DNS_SERVER for $DOMAIN changed to $IP_AAAA" \ | |
https://api.pushover.net/1/messages.json | |
echo "$TIMESTAMP - AAAA record at $DNS_SERVER for $DOMAIN changed to $IP_AAAA" | tee -a "$LOG_FILE" | |
else | |
echo "$TIMESTAMP - no change for AAAA record at $DNS_SERVER for $DOMAIN" | tee -a "$LOG_FILE" | |
fi | |
done | |
sleep 2 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment