-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathgeoip
More file actions
executable file
·33 lines (24 loc) · 739 Bytes
/
Copy pathgeoip
File metadata and controls
executable file
·33 lines (24 loc) · 739 Bytes
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
#!/usr/bin/env perl
use v5.18;
use strict;
use warnings;
use JSON::PP;
use Getopt::Long qw(GetOptions);
use GeoIP2::Database::Reader;
my %args;
GetOptions(
\%args,
"d=s", # Database path. Cannot porceed without one.
);
($args{d} && -f $args{d}) or die "Cannot proceed without a GeoIP database. Specify it like `-d /dir/GeoIP2-City.mmdb`\n";
my $query = shift @ARGV;
(defined($query) && $query ne '') or die "Give me an IP to query\n";
my $reader = GeoIP2::Database::Reader->new(
file => $args{d},
);
my $o = $reader->city( ip => $query );
say JSON::PP->new->utf8->pretty->canonical->encode( $o->raw );
# say $city->city->name;
# say $city->country
# my $country = $city->country();
# print $country->iso_code(), "\n";