9 my $pt = new Net::Patricia;
11 open(COUNTRIES, "< countries.conf") || die "Can't open /etc/powerdns/countries.conf";
13 while (my $line = <COUNTRIES>)
15 if ($line =~ /^(\d+\.\d+\.\d+\.\d+\/\d+)\s+:127\.\d+\.\d+\.\d+:([a-z]{2})/)
20 $pt->add_string($address, $country);
29 while (my $record = <>)
31 if ($record =~ /^\d+\.\d+\s+\d+\s+(\d+\.\d+\.\d+\.\d+)\s+TCP_[A-Z_]+\/\d+\s+(\d+) (?:GET|HEAD|POST) /)
35 my $country = $pt->match_string($ip);
37 $country_bytes{$country} += $bytes if defined($country);
39 $total_bytes += $bytes;
41 elsif ($record =~ /^\d+\.\d+\s+\d+\s+(\d+\.\d+\.\d+\.\d+)\s+UDP_[A-Z_]+\/\d+\s+(\d+) ICP_QUERY /)
51 my %country_bandwidth;
53 while (my($country,$bytes) = each %country_bytes)
55 $country_bandwidth{$country} = $bytes * 250 * 1024 * 1024 / $total_bytes;
58 print Dump(\%country_bandwidth);