| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
use strict; |
| 4 |
|
| 5 |
# The included binary data file "FakeCountry.mmdb" is a minimal MaxMind |
| 6 |
# GeoIP2 database. It was generated using this short perl script, but |
| 7 |
# we're storing the (very small) binary in the git repo directly because |
| 8 |
# the Perl dependency hell for the writer module below is huge. |
| 9 |
|
| 10 |
use MaxMind::DB::Writer::Tree; |
| 11 |
|
| 12 |
my %types = ( |
| 13 |
continent => 'map', |
| 14 |
code => 'utf8_string', |
| 15 |
country => 'map', |
| 16 |
iso_code => 'utf8_string', |
| 17 |
); |
| 18 |
|
| 19 |
my $tree = MaxMind::DB::Writer::Tree->new( |
| 20 |
database_type => 'X', |
| 21 |
languages => ['en'], |
| 22 |
description => { en => 'X', }, |
| 23 |
ip_version => 4, |
| 24 |
record_size => 24, |
| 25 |
remove_reserved_networks => 0, |
| 26 |
map_key_type_callback => sub { $types{ $_[0] } }, |
| 27 |
); |
| 28 |
|
| 29 |
$tree->insert_network('0.0.0.0/1', { |
| 30 |
'continent' => { 'code' => 'NA' }, |
| 31 |
'country' => { 'iso_code' => 'US' }, |
| 32 |
}); |
| 33 |
|
| 34 |
$tree->insert_network('128.0.0.0/1', { |
| 35 |
'continent' => { 'code' => 'EU' }, |
| 36 |
'country' => { 'iso_code' => 'FR' }, |
| 37 |
}); |
| 38 |
|
| 39 |
# Write the database to disk. |
| 40 |
open my $fh, '>:raw', 'FakeCountry.mmdb'; |
| 41 |
$tree->write_tree( $fh ); |