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.