对于一个大型域名数据集,这个方法可以快速完成,而且不需要解析结果;一个IP地址总是在$results{$domain}[0][4]
中。虽然不是单个查询,但它们将同时进行(任何时候最多10个查询正在进行),因此将很快完成。只需确保DNS服务器操作员不会在短时间内对这么多请求有问题。
use AnyEvent::DNS;
use Data::Dumper;
my @domains = qw/google.com/;
my $resolver = AnyEvent::DNS->new( server => '8.8.4.4' );
my %results;
my $done = AE::cv;
$done->begin( sub { shift->send } );
for my $domain (@domains) {
$done->begin;
$resolver->resolve($domain, 'a', sub {push @{$results{$domain}}, \@_; $done->end;});
}
$done->end;
$done->recv;
print Dumper \%results;
输出:
$VAR1 = {
'google.com' => [
[
'google.com',
'a',
'in',
300,
'74.125.225.52'
],
[
'google.com',
'a',
'in',
300,
'74.125.225.50'
],
[
'google.com',
'a',
'in',
300,
'74.125.225.49'
],
[
'google.com',
'a',
'in',
300,
'74.125.225.48'
],
[
'google.com',
'a',
'in',
300,
'74.125.225.51'
]
]
};