Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: query dns by hostname

by skx (Parson)
on Mar 25, 2014 at 12:50 UTC ( #1079673=note: print w/replies, xml ) Need Help??


in reply to query dns by hostname

This is a simple example - but note that you might be seeing failures because the host you're querying win isn't fully-qualified..?

#!/usr/bin/perl use strict; use warnings; use Net::DNS; sub lookupHost { my( $host ) = ( @_ ); my @results; my $res = Net::DNS::Resolver->new; my $query = $res->search($host); if ($query) { foreach my $rr ($query->answer) { push( @results, $rr->address ) if ( $rr->type eq "A" ); } } else { warn "query failed: ", $res->errorstring, "\n"; } return( @results ); } my @out = lookupHost( "google.com" ); foreach my $ip ( @out ) { print "result: $ip\n"; }
Steve
--

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2021-03-04 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (107 votes). Check out past polls.

    Notices?