scripts: moved important shell / perl scripts to scripts/ instead of contrib
[netsniff-ng.git] / contrib / misc / denyhosts.pl
blob790f655d4836fb5223a1a45993924f0ca6c48e92
1 #!/usr/bin/perl
4 # A tiny Perl hack that makes a country statistic of your /etc/hosts.deny
5 # Copyright 2011 Daniel Borkmann <borkmann@netsniff-ng.org>
6 # Subject to the GNU GPL, version 2.
7 # Debian Dep: libgeo-ip-perl
10 use warnings;
11 use strict;
12 use Geo::IP;
14 my %ht;
15 my $db = Geo::IP->new(GEOIP_MEMORY_CACHE);
16 open IN, "<", "/etc/hosts.deny" or die $!;
17 while (<IN>) {
18 my $country;
19 next if (/^\s*#/);
20 next if (/^\s+$/);
21 if (/^\s*\S+:\s*([0-9\.]+)\s*$/) {
22 $country = $db->country_name_by_addr($1);
23 if (defined($country)) {
24 $ht{$country}++;
26 } elsif (/^\s*\S+:\s*(\S+)\s*$/) {
27 $country = $db->country_name_by_name($1);
28 if (defined($country)) {
29 $ht{$country}++;
33 close IN;
34 foreach (keys(%ht)) {
35 print "$_: $ht{$_}\n";