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
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:
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.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"; } }
|
|---|
| 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 |