source: lab.git/misc/dnsbench.pl @ 4be622f

trunk
Last change on this file since 4be622f was dff3e87, checked in by mitty <mitty@…>, 13 years ago
  • benchmark for DNS resolver
  • get domain lists from mail.log

git-svn-id: https://lab.mitty.jp/svn/lab/trunk@126 7d2118f6-f56c-43e7-95a2-4bb3031d96e7

  • Property mode set to 100644
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 || 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 LIST, "<$hostlist";
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.