Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Do you know where your variables are?
 
PerlMonks  

Re: DNS Lookup

by Khen1950fx (Canon)
on Jan 20, 2012 at 10:09 UTC ( #948921=note: print w/ replies, xml ) Need Help??


in reply to DNS Lookup

I'm familiar with the information that you have read. It was almost cool 10 years ago, but time marches on. As an experiment, here are two scripts: one uses Socket, and the second one uses Net::DNS. You'll find that Socket isn't satisfactory.

Socket

#!/usr/bin/perl -l use strict; use warnings; use IO::Socket; use Socket qw(SOCK_STREAM getaddrinfo); my $hostname = 'www.perlmonks.org'; my ($err, @res) = getaddrinfo($hostname, "", {socktype => SOCK_STREAM}); die "Cannot getaddrinfo - $err" if $err; foreach my $ai (@res) { my ($err, $ipaddr) = getnameinfo($ai->{'addr'}, 'NI_NUMERICHOST', 'NIx_NOSERV'); die "Cannot getnameinfo - $err" if $err; print "$ipaddr"; }

Net::DNS

#!/usr/bin/perl use strict; use warnings; use Net::DNS; my $host = 'www.perlmonks.org'; my $res = Net::DNS::Resolver->new; my $query = $res->search($host); if ($query) { foreach my $rr ($query->answer) { next unless $rr->type eq "A"; print $rr->address, "\n"; } } else { warn "Query failed: ", $res->errorstring; }


Comment on Re: DNS Lookup
Select or Download Code
Re^2: DNS Lookup
by jaldama (Acolyte) on Jan 20, 2012 at 21:01 UTC
    Socket did the trick for now but I did have Net::DNS in mind and will keep it there for more robust projects

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (16)
As of 2014-04-24 11:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (565 votes), past polls