我想用来AnyEvent::DNS
在某些 DNS 服务器上解析我的域。服务器列表来自两个地方,每个地方大约有 60 多个服务器。当我只为一个服务器列表运行解析时,没问题。但是如果我为所有列表运行解析,我得到一个错误:"unable to create either an IPv4 or an IPv6 socket"
.
我的脚本如下:
#!/usr/bin/perl
use Modern::Perl;
use AnyEvent::DNS;
use AnyEvent::Socket;
use AnyEvent;
use Module::Runtime qw/require_module/;
use lib './lib';
my $domain = $ARGV[0] // 'fmn.xnimg.cn';
my $cv = AnyEvent->condvar;
for my $mod ( ( 'DNS::xixik', 'DNS::yqie' ) ) { # error
#for my $mod ( ( 'DNS::xixik' ) ) { # ok
require_module($mod);
my $dnslist = $mod->new->get_dnslist;
for my $isp ( keys %$dnslist ) {
while ( my ( $addr, $dns ) = each %{ $dnslist->{$isp} } ) {
resolv( $isp . $addr, $_, $domain ) for @{$dns};
}
}
}
$cv->recv;
sub resolv {
my ( $addr, $dns, $domain ) = @_;
my $resolver = AnyEvent::DNS->new(
server => [ AnyEvent::Socket::parse_address $dns ],
);
$cv->begin;
$resolver->resolve(
"$domain" => 'a',
sub {
my @ips = map { $_->[-1] } @_;
printf "%s (%s) => %s\n", $dns, $addr, join( ", ", @ips ) if @ips;
$cv->end;
}
);
}