App-geoip
view release on metacpan or search on metacpan
* Work around groff-1.24
* It is 2024
* Tested with perl-5.40
* It is 2025
* Add SECURITY.md
0.17 - 2023-01-06, H.Merijn Brand
* It is 2023
0.16 - 2022-01-02, H.Merijn Brand
* Add IP::Geolocation::MMDB to SEE ALSO
0.15 - 2022-01-01, H.Merijn Brand
* It is 2021
* Use $GEOIP_HOST as default for IP/Host
* It is 2022
0.14 - 2020-12-23, H.Merijn Brand
* geological -> geographical (Shlomi Fish)
* Use Pod::Text
* Give more diagnostics if a database connection fails
* Fix META issue for bugtracker
0.13 - 2020-04-09, H.Merijn Brand
* Make 5.14.0 explicit in Makefile.PL
0.12 - 2020-04-09, H.Merijn Brand
* Add option to select CIDR's for country
* Full manual
* Support configuration file(s)
0.07 - 2019-03-09, H.Merijn Brand
* Use Data::Peek for diagnoses or Data::Dumper if not installed
* Use alternatives to determine own location
0.06 - 2019-04-11, H.Merijn Brand
* Add -s/--short
* Use GIS::Distance if available
* Add alternative geolocation url
0.05 - 2019-01-31, H.Merijn Brand
* Add ChangeLog
* Add --dist option
* Add support for SQLite
0.04 - 2018-11-26, H.Merijn Brand
* Initial release to github
* README updates
* Progress on DB loading
## GeoIP2
Based on [PerlMonks](https://www.perlmonks.org/) posts
[1226112](https://www.perlmonks.org/?node_id=1226112) and
[1226223](https://www.perlmonks.org/?node_id=1226223) by
[cavac](https://www.perlmonks.org/?node_id=890813), this is my attempt in
opening the GeoIP2 data from [MAXMIND](https://dev/maxmind.com)
available [here](https://dev.maxmind.com/geoip/geoip2/geolite2/)
The [download section](https://dev.maxmind.com/geoip/geoip2/geolite2/#Downloads)
has three CSV databases available:
- [Country](http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country-CSV.zip)
- [Provider](http://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN-CSV.zip)
- [City](http://geolite.maxmind.com/download/geoip/database/GeoLite2-City-CSV.zip)
If you download all three, and create a postgres database `geoip`, then
[geoip](geoip) will convert all CSV data to database tables.
## Use
``` sh
$ perl geoip
$ perl geoip 66.39.54.27 209.197.123.153 216.92.34.251
$ perl geoip perlmonks.org
$ export GEOIP_DBI_DSN=dbi:SQLite:dbname=/my/databases/geoip.db
$ perl ./geoip --fetch
```
Depending on the amount of memory you have, this might take a while.
You can also fetch the files yourself
```
$ wget -m -L -nd -np -nH \
http://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN-CSV.zip \
http://geolite.maxmind.com/download/geoip/database/GeoLite2-City-CSV.zip \
http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country-CSV.zip
```
## TODO
- IPv6. The current version only implements the IPv4 part. The CSV files however
also the IPv6 data, so it should not be too hard to add.
## SEE ALSO
This tool uses the following modules from CORE and CPAN:
Thanks to cavac for the inspiration
## AUTHOR
H.Merijn Brand <hmbrand@cpan.org>
## COPYRIGHT AND LICENSE
The GeoLite2 end-user license agreement, which incorporates components of the
Creative Commons Attribution-ShareAlike 4.0 International License 1) can be found
[here](https://www.maxmind.com/en/geolite2/eula) 2). The attribution requirement
may be met by including the following in all advertising and documentation
mentioning features of or use of this database.
This tool uses, but does not include, the GeoLite2 data created by MaxMind,
available from [http://www.maxmind.com](http://www.maxmind.com).
Copyright (C) 2018-2026 H.Merijn Brand. All rights reserved.
This library is free software; you can redistribute and/or modify it under
the same terms as Perl itself.
See [here](https://opensource.org/licenses/Artistic-2.0) 3).
1) [https://creativecommons.org/licenses/by-sa/4.0/](https://creativecommons.org/licenses/by-sa/4.0/)
2) [https://www.maxmind.com/en/geolite2/eula](https://www.maxmind.com/en/geolite2/eula)
3) [https://opensource.org/licenses/Artistic-2.0](https://opensource.org/licenses/Artistic-2.0)
};
sub _dump {
my ($label, $ref) = @_;
print STDERR $use_data_peek
? Data::Peek::DDumper ({ $label => $ref })
: Data::Dumper->Dump ([$ref], [$label]);
} # _dump
# Based on GeoIP2 CSV databases
# City: http://geolite.maxmind.com/download/geoip/database/GeoLite2-City-CSV.zip
# Country http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country-CSV.zip
# ASN http://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN-CSV.zip
my $idx_type = $conf{dsn} =~ m/:Pg/ ? "using btree" : "";
my $truncate = $conf{dsn} =~ m/:SQLite/ ? "delete from" : "truncate table";
unless (grep m/\b country \b/ix => $dbh->tables (undef, undef, undef, undef)) {
say "Create table stamps";
$dbh->do (qq; create table stamps (
name text not null primary key,
stamp bigint);
);
Currently not (yet) used. Documentation only.
=item license-key
command line option : none
default value : Undefined
As downloads are only allowed/possible using a valid MaxMind account, you need
to provide a valid license key in your configuration file. If you do not have
an account, you can sign up L<here|https://www.maxmind.com/en/geolite2/signup>.
=back
=head1 DATABASE
Currently PostgreSQL and SQLite have been tested, but others may (or may not)
work just as well. YMMV. Note that the database need to know the C<CIDR>
field type and is able to put a primary key on it.
MariaDB and MySQL are not supported, as they do not support the concept of
L<DBI>, L<Net::CIDR>, L<Math::Trig>, L<LWP::Simple>, L<Archive::ZIP>,
L<Text::CSV_XS>, L<JSON::PP>, L<GIS::Distance>, L<Net::Whois::IP>,
L<HTML::TreeBuilder>, L<Data::Dumper>, L<Data::Peek>, L<Socket>
L<Geo::Coder::HostIP>, L<Geo::IP>, L<Geo::IP2Location>, L<Geo::IP2Proxy>,
L<Geo::IP6>, L<Geo::IPfree>, L<Geo::IP::RU::IpGeoBase>, L<IP::Country>,
L<IP::Country::DB_File>, L<IP::Country::DNSBL>, L<IP::Info>, L<IP::Location>,
L<IP::QQWry>, L<IP::World>, L<Metabrik::Lookup::Iplocation>, L<Pcore::GeoIP>
L<IP::Geolocation::MMDB>
Check L<CPAN|https://metacpan.org/search?q=geoip> for more.
=head1 THANKS
Thanks to cavac for the inspiration
=head1 AUTHOR
H.Merijn Brand F<E<lt>hmbrand@cpan.orgE<gt>>, aka Tux.
=head1 COPYRIGHT AND LICENSE
The GeoLite2 end-user license agreement, which incorporates components of the
Creative Commons Attribution-ShareAlike 4.0 International License 1) can be found
L<here|https://www.maxmind.com/en/geolite2/eula> 2). The attribution requirement
may be met by including the following in all advertising and documentation
mentioning features of or use of this database.
This tool uses, but does not include, the GeoLite2 data created by MaxMind,
available from [http://www.maxmind.com](http://www.maxmind.com).
Copyright (C) 2018-2026 H.Merijn Brand. All rights reserved.
This library is free software; you can redistribute and/or modify it under
the same terms as Perl itself.
See L<here|https://opensource.org/licenses/Artistic-2.0> 3).
1) https://creativecommons.org/licenses/by-sa/4.0/
2) https://www.maxmind.com/en/geolite2/eula
3) https://opensource.org/licenses/Artistic-2.0
=for elvis
:ex:se gw=75|color guide #ff0000:
=cut
lib/App/geoip.pm view on Meta::CPAN
};
sub _dump {
my ($label, $ref) = @_;
print STDERR $use_data_peek
? Data::Peek::DDumper ({ $label => $ref })
: Data::Dumper->Dump ([$ref], [$label]);
} # _dump
# Based on GeoIP2 CSV databases
# City: http://geolite.maxmind.com/download/geoip/database/GeoLite2-City-CSV.zip
# Country http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country-CSV.zip
# ASN http://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN-CSV.zip
my $idx_type = $conf{dsn} =~ m/:Pg/ ? "using btree" : "";
my $truncate = $conf{dsn} =~ m/:SQLite/ ? "delete from" : "truncate table";
unless (grep m/\b country \b/ix => $dbh->tables (undef, undef, undef, undef)) {
say "Create table stamps";
$dbh->do (qq; create table stamps (
name text not null primary key,
stamp bigint);
);
lib/App/geoip.pm view on Meta::CPAN
Currently not (yet) used. Documentation only.
=item license-key
command line option : none
default value : Undefined
As downloads are only allowed/possible using a valid MaxMind account, you need
to provide a valid license key in your configuration file. If you do not have
an account, you can sign up L<here|https://www.maxmind.com/en/geolite2/signup>.
=back
=head1 DATABASE
Currently PostgreSQL and SQLite have been tested, but others may (or may not)
work just as well. YMMV. Note that the database need to know the C<CIDR>
field type and is able to put a primary key on it.
MariaDB and MySQL are not supported, as they do not support the concept of
lib/App/geoip.pm view on Meta::CPAN
L<DBI>, L<Net::CIDR>, L<Math::Trig>, L<LWP::Simple>, L<Archive::ZIP>,
L<Text::CSV_XS>, L<JSON::PP>, L<GIS::Distance>, L<Net::Whois::IP>,
L<HTML::TreeBuilder>, L<Data::Dumper>, L<Data::Peek>, L<Socket>
L<Geo::Coder::HostIP>, L<Geo::IP>, L<Geo::IP2Location>, L<Geo::IP2Proxy>,
L<Geo::IP6>, L<Geo::IPfree>, L<Geo::IP::RU::IpGeoBase>, L<IP::Country>,
L<IP::Country::DB_File>, L<IP::Country::DNSBL>, L<IP::Info>, L<IP::Location>,
L<IP::QQWry>, L<IP::World>, L<Metabrik::Lookup::Iplocation>, L<Pcore::GeoIP>
L<IP::Geolocation::MMDB>
Check L<CPAN|https://metacpan.org/search?q=geoip> for more.
=head1 THANKS
Thanks to cavac for the inspiration
=head1 AUTHOR
H.Merijn Brand F<E<lt>hmbrand@cpan.orgE<gt>>, aka Tux.
=head1 COPYRIGHT AND LICENSE
The GeoLite2 end-user license agreement, which incorporates components of the
Creative Commons Attribution-ShareAlike 4.0 International License 1) can be found
L<here|https://www.maxmind.com/en/geolite2/eula> 2). The attribution requirement
may be met by including the following in all advertising and documentation
mentioning features of or use of this database.
This tool uses, but does not include, the GeoLite2 data created by MaxMind,
available from [http://www.maxmind.com](http://www.maxmind.com).
Copyright (C) 2018-2026 H.Merijn Brand. All rights reserved.
This library is free software; you can redistribute and/or modify it under
the same terms as Perl itself.
See L<here|https://opensource.org/licenses/Artistic-2.0> 3).
1) https://creativecommons.org/licenses/by-sa/4.0/
2) https://www.maxmind.com/en/geolite2/eula
3) https://opensource.org/licenses/Artistic-2.0
=for elvis
:ex:se gw=75|color guide #ff0000:
=cut
( run in 1.800 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )