Skip to content

Instantly share code, notes, and snippets.

@jreisinger
Created June 21, 2013 00:16
Show Gist options
  • Save jreisinger/5827929 to your computer and use it in GitHub Desktop.
Save jreisinger/5827929 to your computer and use it in GitHub Desktop.
Count countries bruteforcing some port(s).
#!/usr/bin/perl
use strict;
use warnings;
use Geo::IP;
my %country;
while (<>) {
my $ip = $1 if /an ([\d\.]+)$/;
$country{$ip} = 1 if $ip;
}
my %freq;
for my $ip ( keys %country ) {
my $gi = Geo::IP->new(GEOIP_MEMORY_CACHE);
# returns undef if country is unallocated, or not defined in our database
my $country = $gi->country_code_by_addr($ip);
$freq{$country}++;
}
my $total = keys %country;
for my $country ( sort { $freq{$b} <=> $freq{$a} } keys %freq ) {
my $num = $freq{$country};
my $perc = sprintf "%d", $num / $total * 100;
print "$country -- $num ($perc %)\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment