8.1. Geoip

GeoIP utility module.

Usage:

local geoip = require('misc/geoip')

8.1.1. API

geoip.open(file) → geoip_handle
Parameters:
  • file (string) – GeoIP data file.

Load GeoIP data file.

object geoip.GeoIPHandle
GeoIPHandle:country(ip) → country_code
Parameters:
Returns:
  • country_code (string) – Result country code or nil if not found.

Query the country code for an IP address.

8.1.2. Example

local ipv4 = require('protocol/ipv4')
local geoip_module = require('misc/geoip')

local geoip = geoip_module.open('/usr/share/GeoIP/GeoIP.dat')
print(geoip:country(ipv4.addr("8.8.8.8")))