]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/scripts/xt_geoip_build
3 # Converter for MaxMind CSV database to binary, for xt_geoip
4 # Copyright © Jan Engelhardt, 2008-2011
8 use Text
::CSV_XS
; # or trade for Text::CSV
11 my $csv = Text
::CSV_XS
->new({
12 allow_whitespace
=> 1,
18 &Getopt
::Long
::Configure
(qw(bundling));
20 "D=s" => \
$target_dir,
23 if (!-d
$target_dir) {
24 print STDERR
"Target directory $target_dir does not exist.\n";
28 my $dir = "$target_dir/LE";
29 if (!-e
$dir && !mkdir($dir)) {
30 print STDERR
"Could not mkdir $dir: $!\n";
40 while (my $row = $csv->getline(*ARGV
)) {
41 if (!defined($country{$row->[4]})) {
42 $country{$row->[4]} = {
48 my $c = $country{$row->[4]};
50 push(@
{$c->{pool_v4
}}, [$row->[2], $row->[3]]);
53 print STDERR
"\r\e[2K$. entries";
57 print STDERR
"\r\e[2K$. entries total\n";
63 my $country = shift @_;
65 foreach my $iso_code (sort keys %$country) {
66 &dump_one
($iso_code, $country->{$iso_code});
72 my($iso_code, $country) = @_;
73 my($file, $fh_le, $fh_be);
75 printf "%5u IPv4 ranges for %s %s\n",
76 scalar(@
{$country->{pool_v4
}}),
77 $iso_code, $country->{name
};
79 $file = "$target_dir/LE/".uc($iso_code).".iv4";
80 if (!open($fh_le, "> $file")) {
81 print STDERR
"Error opening $file: $!\n";
84 foreach my $range (@
{$country->{pool_v4
}}) {
85 print $fh_le pack("VV", $range->[0], $range->[1]);
86 #print $fh_be pack("NN", $range->[0], $range->[1]);