Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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.


#!/usr/bin/perl -l use strict; use warnings; use IO::Socket; use Socket qw(SOCK_STREAM getaddrinfo); my $hostname = ''; 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"; }


#!/usr/bin/perl use strict; use warnings; use Net::DNS; my $host = ''; 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
Replies are listed 'Best First'.
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?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2015-11-25 15:28 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (681 votes), past polls