Lua library for querying IPv4 addresses against DigitalElement NetAcuity databases which have been exported to a JSON file.
opm get revcontent/lua-resty-digitalelement
# nginx.conf
init_worker_by_lua_block {
de = require("digitalelement")
_, err = de.init({
geo = { file = "/usr/local/digitalelement/geo.json" },
vpn = { file = "/usr/local/digitalelement/vpn.json" }
})
if err then
for k, v in pairs(err) do
ngx.log(ngx.ERR, "Failed to load DigitalElement " .. k .. " database: " .. v)
end
end
}
local res, err = de.lookup("geo", ngx.var.remote_addr)
if err then
ngx.log(ngx.ERR, "IP Geo Lookup Failed: " .. err)
else
ngx.say(res["country"])
ngx.say(res["region"])
ngx.say(res["city"])
-- ... additional database keys
end
local res, err = de.lookup("vpn", ngx.var.remote_addr)
if err then
ngx.log(ngx.ERR,"IP VPN Lookup Failed: " .. err)
else
ngx.say(res["vpn-proxy-type"])
ngx.say(res["vpn-proxy-description"])
ngx.say(res["vpn-proxy-names"])
-- ... additional database keys
end
You'll need to have downloaded your databases to your local pc and install the netacuity-textfile-creator.sh
utility. After doing that run the command below to generate the output file which can be imported by this package.
./netacuity-textfile-creator.sh --db_path=/path/to/db --db=1 --no_compress --output_format=json --output_file=./output.json
If you want to utilize your own data to profile user IP addresses, create a file with
each line being a single JSON string. The required key/value pairs are start-ip
and end-ip
.
{"start-ip":"192.168.0.0","end-ip":"192.168.0.255","name":"My Home Network"}
{"start-ip":"10.0.0.0","end-ip":"10.0.255.255","name":"My Work Network","contact":"user@domain"}
{"start-ip":"74.2.11.3","end-ip":"74.2.11.3","name":"School","note":"Each range can have unique keys."}
- Faster importing of data
- Support CSV & compressed files
- Better tries optimization, currently only the fourth octet is optimized.