Skip to content

Instantly share code, notes, and snippets.

@geraldvillorente
Created October 25, 2022 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldvillorente/afa17e06966ce2098b25e338a73e0437 to your computer and use it in GitHub Desktop.
Save geraldvillorente/afa17e06966ce2098b25e338a73e0437 to your computer and use it in GitHub Desktop.
Get the TTL from the authoritative server
#!/bin/bash

show_help(){
        echo Usage $0 domain
}

if [ -z "$1" ]; then
        show_help
        exit 1
fi

DOMAIN=$1
APEX_DOMAIN=`echo $DOMAIN | sed 's/\(.*\.\)\([^.]*\.[^.]*\)/\2/'`
FIRST_AUTHORITATIVE_NS=$(dig +nssearch $APEX_DOMAIN | awk '$1=="SOA"{sub(".$","",$2);print $2;exit;}')

echo
echo Using authoritative nameserver $FIRST_AUTHORITATIVE_NS

dig @$FIRST_AUTHORITATIVE_NS $@
@geraldvillorente
Copy link
Author

Output should be something like this

Using authoritative nameserver ns-148.awsdns-18.com

; <<>> DiG 9.10.6 <<>> @ns-148.awsdns-18.com pantheon.io
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41964
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;pantheon.io.			IN	A

;; ANSWER SECTION:
pantheon.io.		60	IN	A	23.185.0.2

;; AUTHORITY SECTION:
pantheon.io.		172800	IN	NS	ns-1096.awsdns-09.org.
pantheon.io.		172800	IN	NS	ns-148.awsdns-18.com.
pantheon.io.		172800	IN	NS	ns-1857.awsdns-40.co.uk.
pantheon.io.		172800	IN	NS	ns-924.awsdns-51.net.

;; Query time: 89 msec
;; SERVER: 205.251.192.148#53(205.251.192.148)
;; WHEN: Tue Oct 25 09:47:25 PST 2022
;; MSG SIZE  rcvd: 196

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment