mikejones has asked for the wisdom of the Perl Monks concerning the following question:

All, Why is it when I turn off debug mode, I get no output? I was expecting output similar to what nslookup on UX shows for a simple query. My goal is to look up by NAME and by IP within 2 domains to determine success and failure.
use strict; use warnings; use Carp; <snip> my $res = Net::DNS::Resolver->new( nameservers => [qw(nnnnn.com xxxxx.com)], recurse => 0, debug => 1, ); my $query = $res->query("CLIENT IP"); if ($query) { foreach my $rr ($query->answer) { next unless $rr->type eq "A"; ## Skip if not a host address +record ## print $rr->address, "\n"; } } else { warn "query failed: ", $res->errorstring, "\n"; } thank you!

Replies are listed 'Best First'.
Re: Net::DNS::Resolver v0.61 output
by Krambambuli (Curate) on Oct 24, 2007 at 16:22 UTC
    Add
    use Data::Dumper; ... print Dumper ( $query );
    and you'll probably be able to answer the question by your self.
    Looks like the nameservers you're questioning do answer to your request, but the answer doesn't contain any A records.

    Krambambuli
    ---
    enjoying Mark Jason Dominus' Higher-Order Perl
      yes they do answer with debug on. So was it the intent of the person who wrote this module to have this code act in this way? What I am doing wrong? Do you have a recommendation on how to make this more usable? Yes $query is undef.
      CODE OUTPUT: ;; query(##.##.##.##) ;; setting up an AF_INET() family type UDP socket ;; send_udp(##.##.###.##:53) ;; answer from ###.##.###.##:53 : 43 bytes ;; HEADER SECTION ;; id = 6637 ;; qr = 1 opcode = QUERY aa = 0 tc = 0 rd = 0 ;; ra = 1 ad = 0 cd = 0 rcode = SERVFAIL ;; qdcount = 1 ancount = 0 nscount = 0 arcount = 0 ;; QUESTION SECTION (1 record) ;; ##.##.###.##.in-addr.arpa. IN PTR ;; ANSWER SECTION (0 records) ;; AUTHORITY SECTION (0 records) ;; ADDITIONAL SECTION (0 records) RCODE: SERVFAIL; trying next nameserver ;; send_udp(##.##.###.##:53) ;; answer from ##.##.###.##:53 : 474 bytes ;; HEADER SECTION ;; id = 6637 ;; qr = 1 opcode = QUERY aa = 0 tc = 0 rd = 0 ;; ra = 1 ad = 0 cd = 0 rcode = NOERROR ;; qdcount = 1 ancount = 0 nscount = 13 arcount = 13 ;; QUESTION SECTION (1 record) ;; ##.##.###.##.in-addr.arpa. IN PTR ;; ANSWER SECTION (0 records) ;; AUTHORITY SECTION (13 records) . 10302 IN NS i.root-servers.net. . 10302 IN NS g.root-servers.net. . 10302 IN NS k.root-servers.net. . 10302 IN NS b.root-servers.net. . 10302 IN NS c.root-servers.net. . 10302 IN NS f.root-servers.net. . 10302 IN NS e.root-servers.net. . 10302 IN NS d.root-servers.net. . 10302 IN NS m.root-servers.net. . 10302 IN NS l.root-servers.net. . 10302 IN NS j.root-servers.net. . 10302 IN NS a.root-servers.net. . 10302 IN NS h.root-servers.net. ;; ADDITIONAL SECTION (13 records) i.root-servers.net. 10302 IN A 192.36.148.17 g.root-servers.net. 10302 IN A 192.112.36.4 k.root-servers.net. 10302 IN A 193.0.14.129 b.root-servers.net. 10302 IN A 192.228.79.201 c.root-servers.net. 10302 IN A 192.33.4.12 f.root-servers.net. 10302 IN A 192.5.5.241 e.root-servers.net. 10302 IN A 192.203.230.10 d.root-servers.net. 10302 IN A 128.8.10.90 m.root-servers.net. 10302 IN A 202.12.27.33 l.root-servers.net. 10302 IN A 198.32.64.12 j.root-servers.net. 10302 IN A 192.58.128.30 a.root-servers.net. 10302 IN A 198.41.0.4 h.root-servers.net. 10302 IN A 128.63.2.53 $VAR1 = undef;
        yes they do answer with debug on.

        No, they don't. What you see is what happens with your requests, how the code makes various tries to get the answers you queried for.

        So was it the intent of the person who wrote this module to have this code act in this way?

        I won't comment on that - but rest assured the code is ok and doesn't hide any intent to harm anyone ;)

        What I am doing wrong?

        Now that's a ways better question, really :)

        I believe you do use a tool you're not really controlling to solve a problem that you don't fully understand. No problem, it happens to all of us. Anyway, the first step is to define /understand the sub-problems and then fight them one by one.

        Do you have a recommendation on how to make this more usable? Yes $query is undef.

        Let's work it out - what is the nslookup command you were using ? Is it possible that with nslookup you queried different nameservers...?

        Krambambuli
        ---
        enjoying Mark Jason Dominus' Higher-Order Perl