Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Net::DNS, recursive queries & root nameservers

by JPaul (Hermit)
on Jan 05, 2002 at 01:40 UTC ( [id://136390]=perlquestion: print w/replies, xml ) Need Help??

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

Greetings all,
I have recently become enamoured with Net::DNS, and being able to send and process not only queries, but replies. I have been having good success up until this point, and what appears to me like it should work is, at present, refusing to do so.

I'm attempting to use Net::DNS to complete a step-by-step recursive DNS query, like a "real" DNS server. By this, I'm attempting to take an unknown address to a root nameserver, and then follow the tree of DNS servers down until I get an authoritative answer.
This is not working as I plan, in that when I use Net::DNS to query a root nameserver, instead of returning what I'd expect (a packet with a list of DNS servers to ask next in the 'Authority' section), I get, well, nothing. Net::DNS::Resolver returns an undefined response.
I have traversed the route from root nameserver to the target myself, using 'dig', and everything works - but using Net::DNS, querying the exact same servers, gives me nothing, until I ask the actual authoritative DNS server itself - which, of course, defeats the purpose.
My code is included below to show how I am testing this:

#!/usr/bin/perl -w use strict; use Net::DNS::Resolver; use Net::DNS::Packet; my $ns = shift(@ARGV); # New resolver, use the above nameserver my $res = new Net::DNS::Resolver; $res->nameservers($ns); # Run the query my $res_packet = $res->query("www.slashdot.org"); if (!defined $res_packet) { die("res_packet undefined\n"); } # Process the returned packet so we can read it my $d_packet = bless \%{$res_packet}, "Net::DNS::Packet"; if (!defined $d_packet) { die("d_packet undefined\n"); } print "Packet:\n", $d_packet->string;
Perhaps there is something about the DNS structure that I don't fully understand?
The route I've taken was using A.ROOT-SERVERS.NET, A.GTLD-SERVERS.NET to NS1.ANDOVER.NET... Or 193.0.14.129, 192.5.6.30, 64.28.67.55.

My thanks in helping me to understand this,
JP

-- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

Replies are listed 'Best First'.
Re: Net::DNS, recursive queries & root nameservers
by fokat (Deacon) on Jan 05, 2002 at 03:15 UTC
    I did a few tests, and it looks like ->query is failing bacause there's nothing in the ANSWER section. Try changing the line that reads
    my $res_packet = $res->query("www.slashdot.org");
    with
    my $res_packet = $res->send("www.slashdot.org");
    Then you will be able to access the response packets and decide if you got a delegation or an answer.

    Regards.

      My greatest thanks.
      I reread over the Net::DNS manpage, and sure enough under search() and query() it says:
      "Returns a ... 'undef' if no answers were found".

      I read this to mean if the server was unable to respond (server answer) rather than in the ANSWER section.
      Either its not very clear, or I'm not not very sharp.

      Many thanks,
      JP

      -- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://136390]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-26 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found