* benchmark for DNS resolver
authormitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Sat, 29 Oct 2011 10:25:52 +0000 (10:25 +0000)
committermitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Sat, 29 Oct 2011 10:25:52 +0000 (10:25 +0000)
 * get domain lists from mail.log

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

misc/dnsbench.pl [new file with mode: 0644]
misc/domains.pl [new file with mode: 0644]

diff --git a/misc/dnsbench.pl b/misc/dnsbench.pl
new file mode 100644 (file)
index 0000000..d5d2008
--- /dev/null
@@ -0,0 +1,50 @@
+#! /usr/bin/perl -w
+
+use strict;
+use warnings;
+
+use Net::DNS;
+
+my $hostlist = shift @ARGV || die "usage: $0 list_of_hosts [nameserver]";
+if (! -r $hostlist) {
+    die "$0: cannot read $hostlist";
+}
+my $nameserver = shift @ARGV;
+
+my $res;
+if ($nameserver) {
+    warn "$0: performing DNS query with server($nameserver)";
+    $res = Net::DNS::Resolver->new(
+        nameservers => [$nameserver],
+    );
+}
+else {
+    warn "$0: use system default nameservers";
+    $res = Net::DNS::Resolver->new;
+}
+
+
+open LIST, "<$hostlist";
+while (my $host = <LIST>) {
+    chomp $host;
+    my $query = $res->send($host);
+    if ($query) {
+        print "$host -> ";
+        if ($res->errorstring ne 'NOERROR') {
+            print $res->errorstring, "\n";
+            next;
+        }
+        foreach my $rr ($query->answer) {
+            if ($rr->type eq 'A') {
+                print $rr->address, " ";
+            }
+            elsif ($rr->type eq 'PTR') {
+                print $rr->ptrdname, " ";
+            }
+        }
+        print "\n";
+    }
+    else {
+        warn "$0: query failed: ", $res->errorstring, "\n";
+    }
+}
diff --git a/misc/domains.pl b/misc/domains.pl
new file mode 100644 (file)
index 0000000..4f695dc
--- /dev/null
@@ -0,0 +1,20 @@
+#! /usr/bin/perl -w
+
+use strict;
+use warnings;
+
+my $domain = '\@(([-a-z0-9]+\.)*[a-z]+)';
+
+my $file = shift @ARGV;
+open FILE, $file;
+
+my $domains = {};
+while (my $line = <FILE>) {
+    if ($line =~ /$domain/oi) {
+        $domains->{$1}++;
+    }
+}
+
+foreach my $key (keys %$domains) {
+    print $key, "\t", $domains->{$key}, "\n";
+}