JPaul has asked for the wisdom of the Perl Monks concerning the following question:
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:
Perhaps there is something about the DNS structure that I don't fully understand?#!/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;
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 | |
by JPaul (Hermit) on Jan 05, 2002 at 03:25 UTC |