如何执行反向DNS查找,即如何在Perl中将IP地址解析为其DNS主机名?
gethostbyaddr和类似的电话.看到http://perldoc.perl.org/functions/gethostbyaddr.html
如果您需要更详细的DNS信息,请使用Net :: DNS模块,这是一个示例:
use Net::DNS; my $res = Net::DNS::Resolver->new; # create the reverse lookup DNS name (note that the octets in the IP address need to be reversed). my $IP = "209.85.173.103"; my $target_IP = join('.', reverse split(/\./, $IP)).".in-addr.arpa"; my $query = $res->query("$target_IP", "PTR"); if ($query) { foreach my $rr ($query->answer) { next unless $rr->type eq "PTR"; print $rr->rdatastr, "\n"; } } else { warn "query failed: ", $res->errorstring, "\n"; }
原始来源EliteHackers.info,还有更多细节.
use Socket; $iaddr = inet_aton("127.0.0.1"); # or whatever address $name = gethostbyaddr($iaddr, AF_INET);