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

I am using NET:DNS module for my DNS lookup. It works fine and returns IP4 address but it doesnt return IPv6 addresses. I am using perl 5.10

please find below my program

use Net::DNS; my $res = Net::DNS::Resolver->new(debug=>0, igntc=>1, recurse=>1, retrans=>0, retry=>1); $res->port($nameserverport); $res->nameservers("$nameserver"); $res->usevc(1); $res->tcp_timeout($timeout); $res->srcaddr($srcaddr); $res->srcport($srcport); my %result_set = (); my $ttl = 0x7fffffff; #Query type is "A" ,"MX" ,"CNAME" my $query = Net::DNS::Packet->new($address, "A"); my $response = $res->send($query); if ($response->header->ancount > 0) { foreach my $rr ($response->answer) { my $rr_addr; if ($rr->type eq $querytype && $querytype eq "A"){ $rr_addr = $rr->address; } if ($rr_addr) { $result_set->{$rr_addr} = 1; push(@result, $rr_addr); $ttl = $rr->ttl unless ($ttl < $rr->ttl); } } }
Any help on this will be appreciated.

Replies are listed 'Best First'.
Re: IPV6 support for DNS lookup
by aitap (Curate) on Aug 05, 2014 at 07:22 UTC
    I think that query type "AAAA" is required to get IPv6 addresses.
Re: IPV6 support for DNS lookup
by VinsWorldcom (Prior) on Aug 05, 2014 at 13:44 UTC
    Agree with aitap above, IPv6 requires a query type of "AAAA". Your script has much bigger problems since it doesn't work at all. The following worked for me (Windows 7 x64 / Strawberry 5.18.1 MSWin32-x64-multi-thread):

    use strict; use warnings; use Net::DNS; my $res = Net::DNS::Resolver->new(debug=>0, igntc=>1, recurse=>1, retrans=>0, retry=>1 ); $res->nameservers("8.8.8.8"); my %result_set = (); my $query = Net::DNS::Packet->new("www.google.com", "AAAA"); my $response = $res->send($query); if ($response->header->ancount > 0) { foreach my $rr ($response->answer) { if ($rr->type eq "AAAA") { $result_set{$rr->address} = 1; } } } use Data::Dumper; print Dumper \%result_set;

    Producing:

    VinsWorldcom@C:\Users\VinsWorldcom\tmp> test.pl $VAR1 = { '2607:f8b0:4006:803:0:0:0:1010' => 1 };