プライベートIPアドレスを使用してカスタムMaxmindデータベースを作成する方法。プライベートIPを持つカスタムMaxmindDB(geoip2)
私はこのようなものが必要ですCustomizing Maxmind DB。
私はこれをフォローしようとしましたBuilding Your Own MMDB Database for Fun and Profit。そこでPERLスクリプトを次のように変更しました。
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw(say);
use MaxMind::DB::Writer::Tree;
use Net::Works::Network;
my $filename = 'users.mmdb';
# Your top level data structure will always be a map (hash). The MMDB format
# is strongly typed. Describe your data types here.
# See https://metacpan.org/pod/MaxMind::DB::Writer::Tree#DATA-TYPES
my %types = (
latitude => 'uint32',
longitude => 'uint32',
city => 'utf8_string',
country => 'utf_string',
);
my $tree = MaxMind::DB::Writer::Tree->new(
# "database_type" is some arbitrary string describing the database. At
# MaxMind we use strings like 'GeoIP2-City', 'GeoIP2-Country', etc.
database_type => 'My-IP-Data',
# "description" is a hashref where the keys are language names and the
# values are descriptions of the database in that language.
description =>
{ en => 'My database of IP data', fr => q{Mon Data d'IP}, },
# "ip_version" can be either 4 or 6
ip_version => 4,
# add a callback to validate data going in to the database
map_key_type_callback => sub { $types{ $_[0] } },
# "record_size" is the record size in bits. Either 24, 28 or 32.
record_size => 24,
);
my %address_for_employee = (
'10.1.0.0/16' => {
latitude => -12.9608,
longitude => 40.5078,
city => 'Maputo',
country => 'Mozambique',
},
'10.2.0.0/16' => {
latitude => -25.0519,
longitude => 33.6442,
city => 'Gaza',
country => 'Mozambique',
},
);
for my $address (keys %address_for_employee) {
# Create one network and insert it into our database
my $network = Net::Works::Network->new_from_string(string => $address);
$tree->insert_network($network, $address_for_employee{$address});
}
# Write the database to disk.
open my $fh, '>:raw', $filename;
$tree->write_tree($fh);
close $fh;
say "$filename has now been created";
運がありません。 次のエラーが発生しました: 現在、ノードのないツリーでは反復はできません。レコードタイプ:/usr/local/lib/perl/5.14.2/MaxMind/DB/Writer/Tree.pm行292
プライベートIPアドレスを使用してGEOIP2 DBを作成できますか?
お返事ありがとうございます。私はあなたの言ったことを行うが、残念ながらそれは動作しません。私は今、次のエラーが発生しています。 /usr/local/lib/perl/5.14.2/MaxMind/DB/Writer/Serializer.pm行211の "MaxMind :: DB :: Writer :: Serializer"パッケージを介してオブジェクトメソッド "_encode_utf_string"を見つけることができません。 – Rabbit