Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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; }

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 making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2016-10-25 20:56 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (330 votes). Check out past polls.