]> git.ipfire.org Git - thirdparty/xtables-addons.git/commitdiff
geoip: import scripts for building the xt_geoip database
authorJan Engelhardt <jengelh@medozas.de>
Sat, 24 Jul 2010 09:14:14 +0000 (11:14 +0200)
committerJan Engelhardt <jengelh@medozas.de>
Sat, 24 Jul 2010 09:22:33 +0000 (11:22 +0200)
Makefile.am
configure.ac
doc/changelog.txt
extensions/libxt_geoip.man
geoip/.gitignore [new file with mode: 0644]
geoip/Makefile.am [new file with mode: 0644]
geoip/geoip_csv_iv0.pl [new file with mode: 0755]
geoip/geoip_download.sh [new file with mode: 0755]

index dab1ca6753aa4c2daf76338ba03ea4ad8d7c4783..27bf6adcc34dad428753dd48987c230a90842fbc 100644 (file)
@@ -1,7 +1,7 @@
 # -*- Makefile -*-
 
 ACLOCAL_AMFLAGS  = -I m4
-SUBDIRS          = extensions
+SUBDIRS          = extensions geoip
 
 man_MANS := xtables-addons.8
 
index 3184437b58c953a4753afc9cb171d829b893f4ab..ff40db3ebdcf26a6f0c224b2ddf58ef4041ebe28 100644 (file)
@@ -74,7 +74,7 @@ fi;
 AC_SUBST([regular_CFLAGS])
 AC_SUBST([kbuilddir])
 AC_SUBST([xtlibdir])
-AC_CONFIG_FILES([Makefile Makefile.iptrules Makefile.mans
+AC_CONFIG_FILES([Makefile Makefile.iptrules Makefile.mans geoip/Makefile
        extensions/Makefile extensions/ACCOUNT/Makefile
        extensions/ipset/Makefile extensions/pknock/Makefile])
 AC_OUTPUT
index 802d9eb9db7ac5e4130ddc60ee2c372a3076d7f1..20891391914b8b5cbe5c9bb1d3f60508ba160551 100644 (file)
@@ -4,6 +4,7 @@ HEAD
 - RAWNAT: IPv6 variants erroneously rejected masks /33-/128
 - new target xt_CHECKSUM
 - xt_length2: add support for IPv6 jumbograms
+- import xt_geoip database scripts
 
 
 Xtables-addons 1.27 (May 16 2010)
index 593fb9387e54ee88c436b456525615eda1147ce2..007caa4ce490b8c683c085d2fd03753cca4b0e96 100644 (file)
@@ -10,8 +10,8 @@ NOTE:
 The country is inputed by its ISO-3166 code.
 .PP
 The extra files you will need is the binary database files. They are generated
-from a country-subnet database with the geoip_csv_iv0.pl tool, available at
-http://jengelh.medozas.de/files/geoip/ . The files MUST be moved to
-/usr/share/xt_geoip/
+from a country-subnet database with the geoip_csv_iv0.pl tool that should be
+available in /usr/lib(exec)/xtables-addons/ . The resulting files MUST be moved
+to /usr/share/xt_geoip/
 as the shared library is statically looking for this pathname (e.g.
 /usr/share/xt_geoip/LE/de.iv0).
diff --git a/geoip/.gitignore b/geoip/.gitignore
new file mode 100644 (file)
index 0000000..46ece0d
--- /dev/null
@@ -0,0 +1,2 @@
+/BE
+/LE
diff --git a/geoip/Makefile.am b/geoip/Makefile.am
new file mode 100644 (file)
index 0000000..8dd9cf9
--- /dev/null
@@ -0,0 +1,3 @@
+# -*- Makefile -*-
+
+pkglibexec_SCRIPTS = geoip_csv_iv0.pl geoip_download.sh
diff --git a/geoip/geoip_csv_iv0.pl b/geoip/geoip_csv_iv0.pl
new file mode 100755 (executable)
index 0000000..435593e
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+#
+#      Converter for MaxMind CSV database to binary, for xt_geoip
+#      Copyright © Jan Engelhardt <jengelh@medozas.de>, 2008
+#
+#      Use -b argument to create big-endian tables.
+#
+use Getopt::Long;
+use IO::Handle;
+use Text::CSV_XS; # or trade for Text::CSV
+use strict;
+
+my %country;
+my %names;
+my $csv = Text::CSV_XS->new({binary => 0, eol => $/}); # or Text::CSV
+my $mode = "VV";
+
+&Getopt::Long::Configure(qw(bundling));
+&GetOptions("b" => sub { $mode = "NN"; });
+
+while (my $row = $csv->getline(*ARGV)) {
+       if (!defined($country{$row->[4]})) {
+               $country{$row->[4]} = [];
+               $names{$row->[4]} = $row->[5];
+       }
+       my $c = $country{$row->[4]};
+       push(@$c, [$row->[2], $row->[3]]);
+       if ($. % 4096 == 0) {
+               print STDERR "\r\e[2K$. entries";
+       }
+}
+
+print STDERR "\r\e[2K$. entries total\n";
+
+foreach my $iso_code (sort keys %country) {
+       printf "%5u ranges for %s %s\n",
+               scalar(@{$country{$iso_code}}),
+               $iso_code, $names{$iso_code};
+
+       open(my $fh, ">".uc($iso_code).".iv0");
+       foreach my $range (@{$country{$iso_code}}) {
+               print $fh pack($mode, $range->[0], $range->[1]);
+       }
+       close $fh;
+}
diff --git a/geoip/geoip_download.sh b/geoip/geoip_download.sh
new file mode 100755 (executable)
index 0000000..c4a05a2
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+rm -f GeoIPv6.csv{,.gz} GeoIPCountryCSV.zip GeoIPCountryWhois.csv;
+wget \
+       http://geolite.maxmind.com/download/geoip/database/GeoIPv6.csv.gz \
+       http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip;
+gzip -d GeoIPv6.csv.gz;
+unzip GeoIPCountryCSV.zip;