source: lab/trunk/misc/dnsbench.pl @ 144

Last change on this file since 144 was 144, checked in by mitty, 12 years ago
  • replace outdated coding style
-> or
  • open with bare word file handle
File size: 1.1 KB
Line 
1#! /usr/bin/perl -w
2
3use strict;
4use warnings;
5
6use Net::DNS;
7
8my $hostlist = shift @ARGV or die "usage: $0 list_of_hosts [nameserver]";
9if (! -r $hostlist) {
10    die "$0: cannot read $hostlist";
11}
12my $nameserver = shift @ARGV;
13
14my $res;
15if ($nameserver) {
16    warn "$0: performing DNS query with server($nameserver)";
17    $res = Net::DNS::Resolver->new(
18        nameservers => [$nameserver],
19    );
20}
21else {
22    warn "$0: use system default nameservers";
23    $res = Net::DNS::Resolver->new;
24}
25
26
27open my $list, '<', $hostlist or die "$0: filename: $!";
28while (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.