-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrdig
executable file
·53 lines (46 loc) · 1.1 KB
/
rdig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# (c) 2020 Leif Sawyer
# License: GPL 3.0 (see https://github.com/akhepcat/)
# Permanent home: https://github.com/akhepcat/Miscellaneous/
# Direct download: https://raw.githubusercontent.com/akhepcat/Miscellaneous/master/rdig
#
PROG=${0##*/}
# rdig host.3ld.2ld.dom
#
# walks backward until it finds the authoritative name server for each tld (excepting '.')
#
FQDN=${1}
FQDN=${FQDN,,} #lowercase it all
FQDN=${FQDN//[0-9a-f:.]/} #zero out bare IPv4/IPv6 addresses
if [ -z "${FQDN}" ];
then
echo "Usage:"
echo -e "\t${PROG} [fqdn]"
exit 1
fi
#restore the original domain from the command line
FQDN=${1}
myfqdn=${FQDN}
while [[ "${myfqdn}" != "${FQDN##*.}" ]]
do
echo "testing ${myfqdn}"
MYSOA=$(dig +short "${myfqdn}" SOA)
if [ -n "${MYSOA}" ]
then
echo -e "${myfqdn} \t IN \t SOA ${MYSOA}"
MYNS=$(dig +short "${myfqdn}" NS)
if [ -n "${MYNS}" ]
then
for NS in ${MYNS}
do
NSIP=$(dig +short ${NS})
echo -e "${myfqdn} \t IN \t NS ${NS} \t A \t ${NSIP}"
done
fi
else
echo "no SOA for ${myfqdn}"
fi
# dig +noall +answer "${myfqdn}" NS
myfqdn=${myfqdn#*.}
echo ""
done