Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/federicoceratto/nim-mmgeoip

MaxMind GeoIP database client for Nim
https://github.com/federicoceratto/nim-mmgeoip

geoip geolocation library nim nim-lang nim-language

Last synced: 13 days ago
JSON representation

MaxMind GeoIP database client for Nim

Awesome Lists containing this project

README

        

## mmgeoip

MaxMind GeoIP library for Nim.

The library uses the link:https://github.com/maxmind/geoip-api-c[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

[source,bash]
----
sudo apt-get install libgeoip1
nimble install mmgeoip
----

[source,nim]
----
# 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.