Giter Club home page Giter Club logo

nim-mmgeoip's Introduction

mmgeoip

MaxMind GeoIP library for Nim.

The library uses the official libgeoip C library to achieve good performance. Using in-memory caching, an IP address lookup takes less than 0.2 us on an Intel i5.

Usage

sudo apt-get install libgeoip1
nimble install mmgeoip
# Country lookup
let g = GeoIP("/usr/share/GeoIP/GeoIP.dat")
echo g.country_code3_by_addr("8.8.8.8")
echo g.country_code_by_addr("8.8.8.8")
echo g.country_name_by_addr("8.8.8.8")
echo g.id_by_addr("8.8.8.8")
g.delete()

# using MEMORY_CACHE
let g = GeoIP("/usr/share/GeoIP/GeoIP.dat", MEMORY_CACHE)
echo g.country_code3_by_addr("8.8.8.8")
g.delete()

# City lookup
let g = GeoIP("/usr/share/GeoIP/GeoLiteCity.dat")
let r = g.record_by_addr("8.8.8.8")
echo r.city
echo r.latitude
echo $r.longitude
echo r.area_code
echo r.country_code
echo r.country_code3
echo r.postal_code
echo r.region
g.delete()

# AS number lookup
let g = GeoIP("/usr/share/GeoIP/GeoIPASNum.dat")
echo g.org_by_addr("8.8.8.8")
g.delete()

# Same for IPv6
let g = GeoIP("/usr/share/GeoIP/GeoIPASNumv6.dat")
echo g.org_by_addr_v6("2a00:1450:400b:c03::8b")
g.delete()

Contributing

Testing and PRs are welcome.

nim-mmgeoip's People

Contributors

federicoceratto avatar oskca 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.