Giter Club home page Giter Club logo

geodata2's Introduction

Erlang OTP application for handling MaxMind(tm) Geoip2 (.mmdb) files.

Features:

  • Supports all types (hopefully) of bases in .mmdb format, both IPv4 and IPv6 ones;
  • Allows opening multiple files;
  • Access to each opened file by atom;
  • Uses access pool for each of the file, by default 4 workers per file. At the moment this number can be changed in compile time only;
  • Allows reloading files and replacing files in each pool without inerrupting or slowing down requests stream;
  • Safe from binary reference leakage, binary parts are getting copied.
  • R15 compatible

The app accepts IPs in {B3:8, B2:8, B1:8, B0:8}, {W7:16, W6:16, W5:16, W4:16, W3:16, W2:16, W1:16, W0:16} and big-endian dword formats.

Example:

Download and unzip GeoLite2-City.mmdb and GeoLite2-Country.mmdb from MaxMind site and put the databases in the priv/ dir.

$make app shell

1> geodata2:start().
ok
2> geodata2:open_base(b, "priv/GeoLite2-City.mmdb").
{ok,<0.39.0>}
3> geodata2:lookup(b, {94, 75, 242, 11}).
{ok,[{<<"registered_country">>,
      [{<<"names">>,
        [{<<"zh-CN">>,<<232,141,183,229,133,176>>},
         {<<"ru">>,
          <<208,157,208,184,208,180,208,181,209,128,208,187,208,
            176,208,189,208,...>>},
         {<<"pt-BR">>,<<"Holanda">>},
    ...
       {<<"geoname_id">>,6255148},
       {<<"code">>,<<"EU">>}]}]}

Shortcut if you don't want to copy too much data between processes, for GeoIP2 Country and GeoIP2 City only:

4> geodata2:lookup_geocity(b, {91,78,223,188}).
{ok,{geocity,<<"RU">>,<<"Moscow">>,524901,37.6156,55.7522}}
5> geodata2:reload_base(b).
ok
6> geodata2:reload_base(b, "priv/GeoLite2-Country.mmdb").
ok
7> geodata2:lookup_geocity(b, {91,78,223,188}).
{ok,{geocity,<<"RU">>,<<>>,undefined,undefined,undefined}}
8> geodata2:lookup(b, {127, 0, 0, 1}).
not_found
9> geodata2:lookup(b, {127, 0, 0, 1, 1}).
{error,format}

A MaxMind repo with a number of test bases: MaxMind-DB

This application uses some bits and pieces from egeoip

geodata2's People

Contributors

choyunsung avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.