logswan

Fast Web log analyzer using probabilistic data structures
Log | Files | Refs | README | LICENSE

logswan.pl (1462B)


      1 #!/usr/bin/env perl
      2 use strict;
      3 use warnings;
      4 
      5 use MaxMind::DB::Writer::Tree;
      6 use Text::CSV;
      7 
      8 my %types = (
      9     names     => 'map',
     10     continent => 'map',
     11     country   => 'map',
     12     code      => 'utf8_string',
     13     iso_code  => 'utf8_string',
     14     en        => 'utf8_string'
     15 );
     16 
     17 my $tree = MaxMind::DB::Writer::Tree->new(
     18     ip_version            => 6,
     19     record_size           => 32,
     20     database_type         => 'Logswan',
     21     languages             => ['en'],
     22     description           => { en => 'Logswan IP geolocation test data' },
     23     map_key_type_callback => sub { $types{ $_[0] } }
     24 );
     25 
     26 my $au = {
     27     continent => { code     => "OC" },
     28     country   => { iso_code => "AU", names => { en => "Australia" } }
     29 };
     30 
     31 my $de = {
     32     continent => { code     => "EU" },
     33     country   => { iso_code => "DE", names => { en => "Germany" } }
     34 };
     35 
     36 my $fr = {
     37     continent => { code     => "EU" },
     38     country   => { iso_code => "FR", names => { en => "France" } }
     39 };
     40 
     41 my $us = {
     42     continent => { code     => "NA" },
     43     country   => { iso_code => "US", names => { en => "United States" } }
     44 };
     45 
     46 $tree->insert_network( '1.1.1.1/32', $au );
     47 $tree->insert_network( '2.2.2.2/32', $fr );
     48 $tree->insert_network( '3.3.3.3/32', $us );
     49 $tree->insert_network( '4.4.4.4/32', $us );
     50 $tree->insert_network( '5.5.5.5/32', $de );
     51 $tree->insert_network( '6.6.6.6/32', $us );
     52 $tree->insert_network( '7.7.7.7/32', $us );
     53 
     54 open my $db, '>:raw', 'logswan.mmdb';
     55 $tree->write_tree($db);