in reply to Efficient DNS lookup
I would avoid using Net::DNS unless you are doing fancy stuff (in which case it's the only game in town). Perl lets you tap into your DNS resolver's code via gethostbyaddr. The following code should get you started.
#! /usr/bin/perl -w use strict; use Socket; while( <> ) { chomp; my $host; if( $host = gethostbyaddr( inet_aton($_), AF_INET )) { print "$_ resolves to $host\n"; } else { print "$_ has no DNS information\n"; } }
What you might want to do is cache the resolved hostnames to disk and access it either by a tied hash, or load it into memory at start as a hash, depending on your available memory. Looking up DNS names is inherently slow... if you can cache the results you'll make serious time savings.
update: it's hard to say from your example, but on the off chance that you're going the other way (hostnames to IP addresses)...
#! /usr/bin/perl -w use strict; use Socket; while( <> ) { chomp; my $ip; if( $ip = gethostbyname( $_ )) { print "$_ resolves to " . inet_ntoa($ip) . "\n"; } else { print "$_ has no DNS information\n"; } }
|
|---|