source: lab.git/misc/dnsbench.pl @ 55d0513

Last change on this file since 55d0513 was acce401, checked in by mitty <mitty@…>, 12 years ago
  • replace outdated coding style
-> or
  • open with bare word file handle

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

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[dff3e87]1#! /usr/bin/perl -w
2
3use strict;
4use warnings;
5
6use Net::DNS;
7
[acce401]8my $hostlist = shift @ARGV or die "usage: $0 list_of_hosts [nameserver]";
[dff3e87]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
[acce401]27open my $list, '<', $hostlist or die "$0: filename: $!";
28while (my $host = <$list>) {
[dff3e87]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.