Skip to content

Instantly share code, notes, and snippets.

@codesnik
Created December 27, 2015 02:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codesnik/2e0cd34bd98c7c2e4daf to your computer and use it in GitHub Desktop.
Save codesnik/2e0cd34bd98c7c2e4daf to your computer and use it in GitHub Desktop.
it creates 'empty.mmdb', empty MaxMind geoip database, good enough for your tests
#!/usr/local/bin/perl
# run 'mcpan MaxMind::DB::Writer' beforehand
use MaxMind::DB::Writer::Tree;
use Net::Works::Network;
my %types = (
#color => 'utf8_string',
#dogs => [ 'array', 'utf8_string' ],
#size => 'uint16',
);
my $tree = MaxMind::DB::Writer::Tree->new(
ip_version => 6,
record_size => 28,
database_type => 'GeoLite2-City',
languages => ['en', 'ru'],
description => { en => 'GeoLite2 City database (empty)' },
map_key_type_callback => sub { $types{ $_[0] } },
);
# my $network = Net::Works::Network->new_from_string( string => '2001:db8::/48' );
# $tree->insert_network(
# $network,
# {
# color => 'blue',
# dogs => [ 'Fido', 'Ms. Pretty Paws' ],
# size => 42,
# },
# );
open my $fh, '>:raw', 'empty.mmdb';
$tree->write_tree($fh);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment