Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: query dns by hostname

by skx (Parson)
on Mar 25, 2014 at 12:50 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1079673]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-19 01:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found