File: axfr.sh

package info (click to toggle)
thc-ipv6 3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,216 kB
  • ctags: 1,497
  • sloc: ansic: 51,382; sh: 512; makefile: 63; perl: 34
file content (18 lines) | stat: -rwxr-xr-x 759 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash
test -z "$1" -o "$1" = "-h" && { echo Syntax: $0 domain ; echo data is saved to domain-ns.zone ; exit 1; } 

which dig > /dev/null 2>&1 || { echo Error: you need the dig command in your path ; exit 1 ; }

DNS=""
dig 1.0.0.1.0.0.0.0.3.0.0.2.ip6.arpa. ns | grep -q '^1\.0.*SOA' || DNS="@8.8.8.8"
DOMAIN=$1
X=`echo $1 | sed 's/\.$//'`
echo $1 | grep -q '\.$' || DOMAIN=$DOMAIN.

for j in `dig $DNS $DOMAIN ns | grep -w NS | grep -w IN | grep -v '^;' | awk '{print$5}'`; do
  echo Trying zone transfer of $DOMAIN on $j ...
  Y=`echo $j | sed 's/\.$//'`
  dig @$j $DOMAIN axfr > $X-$Y.zone
  grep -w NS $X-$Y.zone | grep -v '^;' | grep -q NS && echo Zone saved to $X-$Y.zone
  grep -w NS $X-$Y.zone | grep -v '^;' | grep -q NS || rm -f $X-$Y.zone
done