trunk
Line | |
---|
1 | #! /usr/bin/perl -w |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | |
---|
6 | use Net::DNS; |
---|
7 | |
---|
8 | my $hostlist = shift @ARGV || die "usage: $0 list_of_hosts [nameserver]"; |
---|
9 | if (! -r $hostlist) { |
---|
10 | die "$0: cannot read $hostlist"; |
---|
11 | } |
---|
12 | my $nameserver = shift @ARGV; |
---|
13 | |
---|
14 | my $res; |
---|
15 | if ($nameserver) { |
---|
16 | warn "$0: performing DNS query with server($nameserver)"; |
---|
17 | $res = Net::DNS::Resolver->new( |
---|
18 | nameservers => [$nameserver], |
---|
19 | ); |
---|
20 | } |
---|
21 | else { |
---|
22 | warn "$0: use system default nameservers"; |
---|
23 | $res = Net::DNS::Resolver->new; |
---|
24 | } |
---|
25 | |
---|
26 | |
---|
27 | open LIST, "<$hostlist"; |
---|
28 | while (my $host = <LIST>) { |
---|
29 | chomp $host; |
---|
30 | my $query = $res->send($host); |
---|
31 | if ($query) { |
---|
32 | print "$host -> "; |
---|
33 | if ($res->errorstring ne 'NOERROR') { |
---|
34 | print $res->errorstring, "\n"; |
---|
35 | next; |
---|
36 | } |
---|
37 | foreach my $rr ($query->answer) { |
---|
38 | if ($rr->type eq 'A') { |
---|
39 | print $rr->address, " "; |
---|
40 | } |
---|
41 | elsif ($rr->type eq 'PTR') { |
---|
42 | print $rr->ptrdname, " "; |
---|
43 | } |
---|
44 | } |
---|
45 | print "\n"; |
---|
46 | } |
---|
47 | else { |
---|
48 | warn "$0: query failed: ", $res->errorstring, "\n"; |
---|
49 | } |
---|
50 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.