9 my $pt = new Net::Patricia;
 
  11 open(COUNTRIES, "< /etc/powerdns/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+) /)
 
  35         my $country = $pt->match_string($ip);
 
  37         $country_bytes{$country} += $bytes if defined($country);
 
  39         $total_bytes += $bytes;
 
  47 my %country_bandwidth;
 
  49 while (my($country,$bytes) = each %country_bytes)
 
  51     $country_bandwidth{$country} = $bytes * 250 * 1024 * 1024 / $total_bytes;
 
  54 print Dump(\%country_bandwidth);