I'm writing a script to query DNS for a list of all servers in a domain, since we'll be taking it over soon. Using the axfr method of Net::DNS::Resolver, I get a response, but not an array of values (DNS RR records) as I'd expect. I looked at this node, but it didn't help. I use the same code as what's there. Does anyone know if the DNS server has to be configured, or if it might be tied down so it sends me a NXDOMAIN result (see below), e.g. for security reasons?

I have the following code:

ZoneXFer('domain.name'); ... sub ZoneXFer { my $domain = pop @_; print "Querying DNS for $domain - Zone transfer ...\n"; my $res = Net::DNS::Resolver->new ( recurse => 1, debug => 1, ); my @zone = $res->axfr($domain); print Dumper($res); foreach $rr (@zone) { $rr->print; } print "\n"; }
When I run it, I get the following:
$ perl cmp_hosts.pl Querying DNS for domain.name - Zone transfer ... ;; axfr_start(domain.name, IN) ;; axfr_start nameserver = 198.205.83.10 ;; read_tcp: expecting 2 bytes ;; read_tcp: received 2 bytes ;; read_tcp: expecting 37 bytes ;; read_tcp: received 37 bytes ;; received 37 bytes ;; HEADER SECTION ;; id = 32651 ;; qr = 1 opcode = QUERY aa = 0 tc = 0 rd = 1 ;; ra = 0 ad = 0 cd = 0 rcode = NXDOMAIN ;; qdcount = 1 ancount = 0 nscount = 0 arcount = 0 ;; QUESTION SECTION (1 record) ;; domain.name. IN AXFR ;; ANSWER SECTION (0 records) ;; AUTHORITY SECTION (0 records) ;; ADDITIONAL SECTION (0 records) ;; Response code from server: NXDOMAIN $VAR1 = bless( { 'persistent_tcp' => 0, 'cdflag' => 1, 'stayopen' => 0, 'querytime' => undef, 'udppacketsize' => 0, 'srcaddr' => '0.0.0.0', 'domain' => 'domain.name', 'answersize' => 0, 'answerfrom' => '', 'sockets' => { 'dns_server1_ip:53' => bless( \*Symbol +::GEN0, 'IO::Socket::INET' ) }, 'debug' => 1, 'axfr_soa_count' => 0, 'searchlist' => [ 'domain.name' ], 'defnames' => 1, 'retrans' => 5, 'tcp_timeout' => 120, 'errorstring' => 'Response code from server: NXDOMAIN +', 'nameservers' => [ 'dns_server1_ip', 'dns_server2_ip' ], 'port' => 53, 'axfr_sel' => bless( [ ', 1, undef, undef, undef, $VAR1->{'sockets'}{'dns_server +1_ip:53'} ], 'IO::Select' ), 'usevc' => 0, 'retry' => 4, 'axfr_rr' => [], 'igntc' => 0, 'dnsrch' => 1, 'recurse' => 1, 'udp_timeout' => undef, 'persistent_udp' => 0, 'dnssec' => 0, 'tsig_rr' => undef, 'srcport' => 0 }, 'Net::DNS::Resolver' );
I also tried putting in this code instead, but it never prints 'here':
$res->axfr_start("$domain"); print Dumper($res); while (my $rr = $res->axfr_next) { print "here\n"; #$rr->print; }

-- Burvil


In reply to axfr method with Net::DNS::Resolver returning zero entries by bowei_99

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.