Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by biosysadmin (Deacon)
on May 17, 2004 at 23:15 UTC ( [id://354125]=note: print w/replies, xml ) Need Help??


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 :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://354125]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 00:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found