How can I make a bulk DNS query using perl on Unix / Linux?

I have a list of systems for which I am trying to get IP addresses. I have successfully used the Net :: DNS module for perl to query the IP address for a single host name. However, I have 1000 systems for which I need IP addresses.

Is there a way to get all these IP addresses with a single request?

If not, is there a way to get the entire list of DNS records, say, for a single domain? If I got this, then I could just put it in a hash and refer to the IP addresses that way.

+4
source share
2 answers

No need to configure Perl. This can be done using the -f option for dig (part of the BIND tools):

 $ dig -f /path/to/host-list.txt 
+10
source

For a large domain data set, this will do it quickly, without the real need to analyze the results; IP will always be in $results{$domain}[0][4] . This is not a single request, but they will be executed at the same time (maximum 10 requests in process at any time by IIRC), so this will be done quickly. Just make sure that the DNS server operator does not have a problem with so many queries in a short period of time.

 use AnyEvent::DNS; use Data::Dumper; my @domains = qw/google.com/; my $resolver = AnyEvent::DNS->new( server => '8.8.4.4' ); my %results; ### Set up the condvar my $done = AE::cv; $done->begin( sub { shift->send } ); for my $domain (@domains) { $done->begin; $resolver->resolve($domain, 'a', sub {push @{$results{$domain}}, \@_; $done->end;}); } ### Decrement the cv counter to cancel out the send declaration $done->end; ### Wait for the resolver to perform all resolutions $done->recv; print Dumper \%results; 

Outputs:

 $VAR1 = { 'google.com' => [ [ 'google.com', 'a', 'in', 300, '74.125.225.52' ], [ 'google.com', 'a', 'in', 300, '74.125.225.50' ], [ 'google.com', 'a', 'in', 300, '74.125.225.49' ], [ 'google.com', 'a', 'in', 300, '74.125.225.48' ], [ 'google.com', 'a', 'in', 300, '74.125.225.51' ] ] }; 
+3
source

All Articles