-
-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathgenerate_mmdb.pl
More file actions
executable file
·89 lines (78 loc) · 2.7 KB
/
generate_mmdb.pl
File metadata and controls
executable file
·89 lines (78 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!perl
use MaxMind::DB::Writer::Tree;
my %city_types = (
city => 'map',
code => 'utf8_string',
continent => 'map',
country => 'map',
en => 'utf8_string',
is_in_european_union => 'boolean',
iso_code => 'utf8_string',
latitude => 'double',
location => 'map',
longitude => 'double',
metro_code => 'utf8_string',
names => 'map',
postal => 'map',
subdivisions => ['array', 'map'],
region => 'utf8_string',
time_zone => 'utf8_string',
);
my $city_tree = MaxMind::DB::Writer::Tree->new(
ip_version => 6,
record_size => 24,
database_type => 'GeoLite2-City',
languages => ['en'],
description => { en => 'Test database of IP city data' },
map_key_type_callback => sub { $city_types{ $_[0] } },
);
$city_tree->insert_network(
'44.55.66.77/32',
{
city => { names => {en => 'San Diego'} },
continent => { code => 'NA', names => {en => 'North America'} },
country => { iso_code => 'US', names => {en => 'United States'} },
is_in_european_union => false,
location => {
latitude => 37.751,
longitude => -97.822,
metro_code => 'custom metro code',
time_zone => 'America/Los Angeles',
},
postal => { code => 'custom postal code' },
subdivisions => [
{ iso_code => 'ABC', names => {en => 'Absolute Basic Class'} },
],
},
);
my $outfile = ($ENV{'DATA_DIR'} || '/data/') . ($ENV{'CITY_FILENAME'} || 'test_city.mmdb');
open my $fh, '>:raw', $outfile;
$city_tree->write_tree($fh);
my %country_types = (
country => 'map',
iso_code => 'utf8_string',
names => 'map',
en => 'utf8_string',
);
my $country_tree = MaxMind::DB::Writer::Tree->new(
ip_version => 6,
record_size => 24,
database_type => 'GeoLite2-Country',
languages => ['en'],
description => { en => 'Test database of IP country data' },
map_key_type_callback => sub { $country_types{ $_[0] } },
);
$country_tree->insert_network(
'8.8.8.8/32',
{
country => {
iso_code => 'US',
names => {
en => 'United States',
},
},
},
);
my $outfile = ($ENV{'DATA_DIR'} || '/data/') . ($ENV{'COUNTRY_FILENAME'} || 'test_country.mmdb');
open my $fh, '>:raw', $outfile;
$country_tree->write_tree($fh);