-
Notifications
You must be signed in to change notification settings - Fork 3
/
dns_zonetransfer.pl
executable file
·56 lines (38 loc) · 1.18 KB
/
dns_zonetransfer.pl
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
54
55
56
#!/usr/bin/env perl
# Description: Perform a zone transfer
# Depends on: p5-net-dns
#
# (c) 2020 Alexandr Savca, alexandr dot savca89 at gmail dot com
use strict;
use warnings;
use Net::DNS;
my $hostname = shift or die <<EOF;
Requests a zone transfer (AXFR) from a DNS servers.
Usage: $0 <HOSTNAME>
EOF
my $res = Net::DNS::Resolver->new;
# Find the nameservers for the domain
my $reply = $res->query($hostname, 'NS');
die 'query failed: ' . $res->errorstring . "\n" unless $reply;
my @nameservers = grep { $_->type eq 'NS' } $reply->answer;
@nameservers = sort { $a->nsdname cmp $b->nsdname } @nameservers;
my @nsdnames;
push(@nsdnames, $_->nsdname) for @nameservers;
print <<EOF;
Perform a zone transfer for:
\@DOMAIN $hostname
\@NAMESERVERS @nsdnames
EOF
for my $nsd (@nsdnames) {
my $nsdlen = length $nsd;
my $hyphlen = (76 / 2) - $nsdlen;
print '-' x $hyphlen . "[ $nsd ]" . '-' x $hyphlen . "\n";
$res->tcp_timeout(20);
$res->nameservers($nsd);
my @zone = $res->axfr($hostname);
warn $res->errorstring . "\n" if $res->errorstring ne 'NOERROR';
$_->print() for @zone;
print "\n";
}
# vim:sw=4:ts=4:sts=4:et:tw=71:cc=72
# End of file.