Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/federicoceratto/nim-mmgeoip
- Owner: FedericoCeratto
- License: lgpl-2.1
- Created: 2016-11-08T17:50:21.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-11-08T18:08:41.000Z (about 8 years ago)
- Last Synced: 2025-01-05T20:41:32.673Z (about 1 month ago)
- Topics: geoip, geolocation, library, nim, nim-lang, nim-language
- Language: Nimrod
- Size: 15.6 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
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.