-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbind-query-report.pl
More file actions
executable file
·80 lines (61 loc) · 2.1 KB
/
Copy pathbind-query-report.pl
File metadata and controls
executable file
·80 lines (61 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/perl
use strict;
use warnings;
use Socket;
my %stats;
while ( defined(my $line=<>) ) {
chomp $line;
# formatting is specific to the local environment, this is one example of how you might see it:
#
# 2019-05-07T23:55:46+00:00 ns1 named[128987]: 07-May-2019 23:55:46.519 client 192.0.2.1#54045 (foo.example.edu): view internal-in: query: foo.example.edu IN A + (10.64.22.100)
next if $line !~ m{ \s client \s ([^\#]+) [#] \d+ \s [\(][^\)]+[\)][:] \s view \s [^:]+ [:] \s query: \s (\S+) \s IN \s (\S+) \s }xms;
my $saddr = $1;
my $qname = lc $2;
my $type = $3;
my ( undef, $ns, undef ) = split /\s+/, $line, 3;
$stats{saddr}{$saddr}++;
$stats{qname}{$qname}++;
$stats{type}{$type}++;
$stats{ns}{$ns}++;
}
my $counter;
print "# BIND query log summary statistics\n";
print "\n";
$counter =1;
printf "%-15s %s\n", '#count', 'client query sources';
for my $saddr ( sort {$stats{saddr}{$b} - $stats{saddr}{$a}} keys %{$stats{saddr}} ) {
printf "%-15s %s (%s)\n", commify($stats{saddr}{$saddr}), $saddr, get_hostname($saddr);
last if $counter++ == 10;
}
print "\n";
$counter = 1;
printf "%-15s %s\n", '#count', 'type';
for my $type ( sort {$stats{type}{$b} - $stats{type}{$a}} keys %{$stats{type}} ) {
printf "%-15s %s\n", commify($stats{type}{$type}), $type;
last if $counter++ == 10;
}
print "\n";
$counter = 1;
printf "%-15s %s\n", '#count', 'qname';
for my $qname ( sort {$stats{qname}{$b} - $stats{qname}{$a}} keys %{$stats{qname}} ) {
printf "%-15s %s\n", commify($stats{qname}{$qname}), $qname;
last if $counter++ == 10;
}
print "\n";
$counter = 1;
printf "%-15s %s\n", '#count', 'name server';
for my $ns ( sort {$stats{ns}{$b} - $stats{ns}{$a}} keys %{$stats{ns}} ) {
printf "%-15s %s\n", commify($stats{ns}{$ns}), $ns;
last if $counter++ == 10;
}
sub get_hostname{
my $addr = shift or return 'NA';
my $name = gethostbyaddr(inet_aton($addr), AF_INET) || '-';
return $name;
}
# from Perl Cookbook
sub commify {
my $text = reverse $_[0];
$text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
return scalar reverse $text;
}