Skip to content
luajit bindings to maxmind geoip
Branch: master
Clone or download
Latest commit 1dae87f Apr 5, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
geoip
spec
Makefile
README.md update readme Apr 5, 2018
dist.ini
geoip-dev-1.rockspec
geoip.lua

README.md

LuaJIT bindings to the C MaxMind GeoIP library

In order to use this library you'll need luajit, libGeoIP, and some geoip databases installed. (Note: libGeoIP is the older C library, that should be already available in most package managers)

Install

luarocks install --server=http://luarocks.org/manifests/leafo geoip

Reference

The module is named geoip

local geoip = require "geoip"

GeoIP has support for many different database types. The available lookup databases are automatically loaded from the system location.

Only the country and ASNUM databases are supported. Feel free to create a pull request with support for more.

lookup_addr(ip_address)

Look up information about an address. Returns an table with properties about that address extracted from all available databases.

local geoip = require "geoip"
local res = geoip.lookup_addr("8.8.8.8")

print(res.country_code)

The structure of the return value looks like this:

{
  country_code = "US",
  country_name = "United States",
  asnum = "AS15169 Google Inc."
}

Controlling database caching

You can control how the databases are loaded by manually instantiating a GeoIP object and calling the load_databases method directly. lookup_addr will automatically load databases only if they haven't been loaded yet.

local geoip = require("geoip")

local gi = geoip.GeoIP()
gi:load_databases("memory")

local res = gi:lookup_addr("8.8.8.8")

By default the STANDARD mode is used, which reads from disk for each lookup

Contact

Author: Leaf Corcoran (leafo) (@moonscript)
Email: leafot@gmail.com
Homepage: http://leafo.net

You can’t perform that action at this time.