in reply to Re: perl to convert text list of ip address to a name
in thread perl to convert text list of ip address to a name

Edit: I'm smoking crack. Sorry saskaqueer. Old thread is shown below ...

I think you have it backwards, the original poster asked for a way to convert IP addresses to hostnames, not hostnames to IP addresses.

Here's some example code using Net::DNS:

use Net::DNS; my @domains = qw/google.com perl.com perlmonks.org cpan.org/; my $res = Net::DNS::Resolver->new; foreach my $domain( @domains ) { my $query = $res->search($domain); if ($query) { foreach my $rr ($query->answer) { next unless $rr->type eq "A"; print $rr->address, "\n"; } } else { warn "query failed: ", $res->errorstring, "\n"; } }
Be forewarned: Net::DNS is a bit slow, but it does get the job done. Printing a CSV list of the domains and their associated IP addresses is an exercise left to the reader.

Replies are listed 'Best First'.
Re^3: perl to convert text list of ip address to a name
by saskaqueer (Friar) on May 18, 2004 at 02:25 UTC
    I think you have it backwards, the original poster asked for a way to convert IP addresses to hostnames, not hostnames to IP addresses.

    What do you think my code does? It reads in a list of IP addresses and converts them to hostnames. Your code on the other hand converts hostnames into (possibly multiple) IP addresses, which is what your quote above says is what the OP did not ask for... You're not making sense. Your text and your code say two different stories :)