这是我正在使用的代码。代码有什么问题?此外,如何指定超时参数?tcp_timeout 似乎不起作用。
sub resolve_dns()
{
my $dns = $_[0];
my $res = Net::DNS::Resolver->new(
nameservers => [qw(24.116.197.232)],
recurse => 0,
debug => 1,
tcp_timeout => 3
);
my $query = $res->search($dns);
if ($query) {
foreach my $rr ($query->answer) {
next unless $rr->type eq "A";
print $rr->address, "\n";
}
} else {
warn "query failed: ", $res->errorstring, "\n";
}
}
这是我得到的输出。
Output
query failed: query timed out
;; search(www.youtube.com)
;; setting up an AF_INET() family type UDP socket
;; send_udp(24.116.197.232:53)
;; send_udp(24.116.197.232:53)
;; send_udp(24.116.197.232:53)
;; send_udp(24.116.197.232:53)