I have a simple script which I want to use to get the authority records for a domain by querying one of the TLD servers, but when I run my script, it says my variable comes back undefined. I placed my Net::DNS::Resolver in debug mode, and it says I am getting a packet back with authority records, so why is my variable undefined?
#!/usr/local/bin/perl use Net::DNS; $domain = $ARGV[0]; #192.48.79.30 is j.gtld-servers.net my $res = Net::DNS::Resolver->new( nameservers => [qw(192.48.79.30)], recurse => 1, debug => 1, ); $packet = $res->query("$domain", 'NS'); @authority = $packet->authority; foreach $rr (@authority) { print $rr->string, "\n"; }
Output:
whiskey> ./sim5.pl happy.com ;; query(happy.com, NS) ;; setting up an AF_INET() family type UDP socket ;; send_udp(192.35.51.30:53) ;; answer from 192.35.51.30:53 : 105 bytes ;; HEADER SECTION ;; id = 55673 ;; qr = 1 opcode = QUERY aa = 0 tc = 0 rd = 1 ;; ra = 0 ad = 0 cd = 0 rcode = NOERROR ;; qdcount = 1 ancount = 0 nscount = 2 arcount = 2 ;; QUESTION SECTION (1 record) ;; happy.com. IN NS ;; ANSWER SECTION (0 records) ;; AUTHORITY SECTION (2 records) happy.com. 172800 IN NS ns6.walgreens.com. happy.com. 172800 IN NS ns7.walgreens.com. ;; ADDITIONAL SECTION (2 records) ns6.walgreens.com. 172800 IN A 204.15.116.4 ns7.walgreens.com. 172800 IN A 204.15.116.132 Can't call method "authority" on an undefined value at ./sim5.pl line +16.

In reply to problem querying TLD nameserver with Net::DNS::Resolver by jiemi

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.