-
Notifications
You must be signed in to change notification settings - Fork 2
/
zone-xfer
executable file
·44 lines (37 loc) · 1.15 KB
/
zone-xfer
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
#!/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/zone-xfer
#
server=${1}
domain=${2}
view=${3}
keyfile=/etc/bind/named.keys
usage() {
echo "$0 server domain [view]"
echo " if [view] is specified, will attempt to read the key from ${keyfile}, parse and use it."
echo " this requires the key name to be equal to the view name"
}
if [ -z "${server}" ]
then
usage
elif [ -z "${domain}" ]
then
usage
else
if [ -n "${view}" ]
then
secret=$(grep -iEw 'key|secret' "${keyfile}" | grep -A1 "${view}" | grep secret | awk '{print $2}' | cut -f 1 -d\; | tr -d [\'\"] )
algo=$(grep -iEw 'key|algorithm' "${keyfile}" | grep -A1 "${view}" | grep algorithm | awk '{print $2}' | cut -f 1 -d\; | tr -d [\'\"] )
if [ -n "${secret}" ]
then
viewk="-y ${algo}:${view}:${secret}"
else
echo "Couldn't find secret for view ${view}"
echo "trying without secrets"
viewk="-y ${view}"
fi
fi
dig axfr @${server} "${domain}" ${viewk}
fi