in reply to Timout a gethostbyaddr?
Another option would be to use Net::DNS::Resolver - at least if you're happy with DNS lookups only (AFAICT, it doesn't do local lookups via /etc/hosts). The Net::DNS suite of modules allows very flexible configuration. Among other things you can configure timeouts, list of nameservers to query and number of retries per server (those should be the most interesting options to reduce lookup times...).
Here's a simple example, which you can use for both forward and reverse lookups:
use Net::DNS::Resolver; my $res = Net::DNS::Resolver->new( nameservers => [qw(10.0.5.10)], # specify your own here udp_timeout => 2, retry => 1, #debug => 1, ); my $host = '123.123.123.123'; if (my $pkt = $res->query($host)) { for my $answer ( $pkt->answer() ) { my $type = $answer->type(); if ($type eq "PTR") { print $answer->ptrdname(), "\n"; } elsif ($type eq "A") { print $answer->name(), "\n"; } } }
|
|---|