memo.xight.org

日々のメモ

Net::DNS

Install

# aptitude install libnet-dns-perl


nslookuper.pl

#!/usr/bin/perl
use Net::DNS;
my $res   = Net::DNS::Resolver->new;
while (<>){
	chomp;
	my $host  = $_;
	my $query = $res->search($host);

	if ($query) {
		foreach my $rr ($query->answer) {
			next unless $rr->type eq "A";
			my $address = $rr->address;
			printf("%-20s : %14s\n" ,$host,$address);
		}
	} else {
		warn "query failed: ", $res->errorstring, "\n";
	}
}

usage

$ cat list
www.example.com
www.exmaple.net
www.example.org
$ nslookuper.pl < list
www.example.com : 192.0.34.166
www.example.net : 192.0.34.166
www.example.org : 192.0.34.166


Reference

Net::DNS