From e93445a95d07b9fbc963d324f466c01e80b827d3 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Wed, 24 Apr 2024 19:36:17 -0400 Subject: [PATCH] Add a script to do authoritative DNS queries --- scripts/dig-authoritative | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 scripts/dig-authoritative diff --git a/scripts/dig-authoritative b/scripts/dig-authoritative new file mode 100755 index 0000000..373eda9 --- /dev/null +++ b/scripts/dig-authoritative @@ -0,0 +1,24 @@ +#! /bin/bash +set -e + +# Expect either a domain, or a domain and a record type +if [ $# -lt 1 ] || [ $# -gt 2 ]; then + echo "Usage: dig-authoritative [record type]" + exit 1 +fi + +DOMAIN=$1 +RECORD_TYPE=${2:-A} + +# Look up the authoritative name servers for the domain +AUTH_NS=$(dig +short NS $DOMAIN | head -n 1) + +# If there are no authoritative name servers, the domain doesn't exist +if [ -z "$AUTH_NS" ]; then + echo "Cannot find authoritative name servers for $DOMAIN" >&2 + exit 1 +fi + +# Now, do a proper query +dig @$AUTH_NS $DOMAIN $RECORD_TYPE +exit $?