From: mitty Date: Sat, 29 Oct 2011 10:25:52 +0000 (+0000) Subject: * benchmark for DNS resolver X-Git-Url: http://lab.mitty.jp/git/?a=commitdiff_plain;h=dff3e87bde3c27a391f9906cda4ac694d0fc653f;p=lab.git * 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 --- diff --git a/misc/dnsbench.pl b/misc/dnsbench.pl new file mode 100644 index 0000000..d5d2008 --- /dev/null +++ b/misc/dnsbench.pl @@ -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 = ) { + 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 index 0000000..4f695dc --- /dev/null +++ b/misc/domains.pl @@ -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 = ) { + if ($line =~ /$domain/oi) { + $domains->{$1}++; + } +} + +foreach my $key (keys %$domains) { + print $key, "\t", $domains->{$key}, "\n"; +}