File: bld-mrtg.pl

package info (click to toggle)
bld 0.3.2-3.2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 500 kB
  • ctags: 252
  • sloc: ansic: 2,307; perl: 180; makefile: 143; sh: 106; python: 36
file content (38 lines) | stat: -rwxr-xr-x 1,029 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl
#
# This script reads BLD dump files and prints statistics about the number
# of currently blacklisted IPs and the number of IPs added in the last 5
# minutes.  The default output is MRTG-friendly.
#
# Olivier Beyssac <obld@r14.freenix.org>
#

use strict;

# If you don't use BLD default value for blacklist expiration (-e option
# or blacklist_expiration parameter in bld.conf(5)), change this
my $expiration = 900;

# If you don't run MRTG every 5 minutes, change this
my $rate = 300;

my $dump = "/var/run/bld/bld_blacklist.dump";
my $state = "/var/run/bld-mrtg.state";
my $current_time = time();
my $count = 0;
my $total = 0;

open(BLD, "bldread $dump |");
while (<BLD>) {
        if (/^(\d+\.\d+\.\d+\.\d+;\d+;(\d+);/) {
                my $ip = $1;
                my $time = $2;
                $total++ if ($time > $current_time - $expiration);
                if ($time > $current_time - $rate) {
                        $count++;
                }
        }
}
close(BLD);

print "$count\n$total\n\n\n";