in reply to hostname from ip

The Perl Cookbook Recipe 17.7 discusses this, but you have to have a SOCKET first. Take a look at Net::DNS and Acme::DNS::Correct. From the docs:
use strict; use warnings; use Net::DNS; use Acme::DNS::Correct 'sneaky'; use Data::Dumper; my $res = Net::DNS::Resolver->new; my $query = $res->search("host.example.com"); if ($query) { foreach my $rr ($query->answer) { next unless $rr->type eq "A"; print $rr->address, "\n"; } } else { warn "query failed: ", $res->errorstring, "\n"; }

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re:x2 hostname from ip (use gethostbyaddr)
by grinder (Bishop) on Oct 02, 2003 at 15:19 UTC

    Far too complex!

    #! /usr/bin/perl -w use strict; use Socket; for( @ARGV ) { if( my $host = gethostbyaddr( inet_aton($_), AF_INET )) { print "$_ is $host\n"; } else { print "$_ NXDOMAIN\n"; } }

    Works on my machine :)

    Note that this will return one record. If you are doing funky things with multiple A or PTR records it might miss the information you're interested in. In which case the Net::DNS module will let you iterate through the RR set. Otherwise it's overkill.