lua-resty-ip2location
用于读取 ip2location 地理位置数据库的 Lua 库
$ opm get olegabr/lua-resty-ip2location
名称
lua-resty-ip2location - 用于读取 ip2location 地理位置数据库格式(也称为 ip2location)的 Lua 库。
安装
opm get olegabr/lua-resty-ip2location
摘要
local ip2location = require 'resty.ip2location'
local cjson = require('cjson')
-- ip2location.IP2LOCATION_FILE_IO and ip2location.IP2LOCATION_CACHE_MEMORY are also available
local ip2loc = ip2location.new("/usr/share/ip2location/IPV6-COUNTRY.BIN", ip2location.IP2LOCATION_SHARED_MEMORY)
--support ipv6 e.g. 2001:4860:0:1001::3004:ef68
local record,err = ip2loc:lookup(ngx.var.arg_ip or ngx.var.remote_addr)
if not record then
ngx.log(ngx.ERR,'failed to lookup by ip ,reason:',err)
ip2loc:close()
return
end
ngx.say("full :",cjson.encode(record))
if ngx.var.arg_node then
ngx.say("node name:",ngx.var.arg_node," ,value:", cjson.encode(record[ngx.var.arg_node] or {}))
end
ip2loc:close()
#ipv4
$ curl 'http://localhost?ip=114.114.114.114&node=country_long'
#ipv6
#$ curl 'http://localhost?ip=2001:4860:0:1001::3004:ef68&node=country_long'
full :{"domain":"This parameter is unavailable for selected data file. Please upgrade the data file.","longitude":0,"latitude":0,"mnc":"This parameter is unavailable for selected data file. Please upgrade the data file.","areacode":"This parameter is unavailable for selected data file. Please upgrade the data file.","weatherstationcode":"This parameter is unavailable for selected data file. Please upgrade the data file.","city":"This parameter is unavailable for selected data file. Please upgrade the data file.","timezone":"This parameter is unavailable for selected data file. Please upgrade the data file.","mcc":"This parameter is unavailable for selected data file. Please upgrade the data file.","isp":"This parameter is unavailable for selected data file. Please upgrade the data file.","region":"This parameter is unavailable for selected data file. Please upgrade the data file.","elevation":0,"zipcode":"This parameter is unavailable for selected data file. Please upgrade the data file.","mobilebrand":"This parameter is unavailable for selected data file. Please upgrade the data file.","netspeed":"This parameter is unavailable for selected data file. Please upgrade the data file.","country_long":"China","country_short":"CN","iddcode":"This parameter is unavailable for selected data file. Please upgrade the data file.","weatherstationname":"This parameter is unavailable for selected data file. Please upgrade the data file.","usagetype":"This parameter is unavailable for selected data file. Please upgrade the data file."}
node name:country_long ,value:"China"
美化
{
"domain": "This parameter is unavailable for selected data file. Please upgrade the data file.",
"longitude": 0,
"latitude": 0,
"mnc": "This parameter is unavailable for selected data file. Please upgrade the data file.",
"areacode": "This parameter is unavailable for selected data file. Please upgrade the data file.",
"weatherstationcode": "This parameter is unavailable for selected data file. Please upgrade the data file.",
"city": "This parameter is unavailable for selected data file. Please upgrade the data file.",
"timezone": "This parameter is unavailable for selected data file. Please upgrade the data file.",
"mcc": "This parameter is unavailable for selected data file. Please upgrade the data file.",
"isp": "This parameter is unavailable for selected data file. Please upgrade the data file.",
"region": "This parameter is unavailable for selected data file. Please upgrade the data file.",
"elevation": 0,
"zipcode": "This parameter is unavailable for selected data file. Please upgrade the data file.",
"mobilebrand": "This parameter is unavailable for selected data file. Please upgrade the data file.",
"netspeed": "This parameter is unavailable for selected data file. Please upgrade the data file.",
"country_long": "China",
"country_short": "CN",
"iddcode": "This parameter is unavailable for selected data file. Please upgrade the data file.",
"weatherstationname": "This parameter is unavailable for selected data file. Please upgrade the data file.",
"usagetype": "This parameter is unavailable for selected data file. Please upgrade the data file."
}
先决条件
[IP2Location C 库][https://github.com/chrislim2888/IP2Location-C-Library]
[openresty][https://openresty.org.cn]
[ip2location 数据库][https://www.ip2location.com/]
错误报告
请通过在我们的 GitHub 问题跟踪器上提交问题来报告错误,网址为:https://github.com/olegabr/lua-resty-ip2location/issues
如果错误是由 IP2Location C 库引起的,请在以下网址提交问题:https://github.com/chrislim2888/IP2Location-C-Library/issues
版权和许可
此模块根据 MIT 许可证发布。
版权所有 (C) 2018-,作者 Oleg Abrosimov <olegabrosimovnsk@gmail.com>。
保留所有权利。
特此免费授予获得本软件和相关文档文件(“软件”)副本的任何人无限制地使用本软件的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本的权利,以及允许获得软件的人员在满足以下条件的情况下这样做
上述版权声明和本许可声明应包含在软件的所有副本或重要部分中。
软件“按原样”提供,不提供任何形式的明示或暗示的保证,包括但不限于适销性、特定用途适用性和不侵权的保证。在任何情况下,作者或版权持有人均不对因软件或使用或以其他方式处理软件而引起的任何索赔、损害或其他责任负责,无论是在合同、侵权行为或其他情况下。
作者
Oleg Abrosimov (olegabrosimovnsk@gmail.com)
许可证
mit
版本
-
用于读取 ip2location 地理位置数据库的 Lua 库 2018-02-15 18:47:51
-
用于读取 ip2location 地理位置数据库的 Lua 库 2018-02-15 14:19:14
-
用于读取 ip2location 地理位置数据库的 Lua 库 2018-02-15 14:13:00
-
用于读取 ip2location 地理位置数据库的 Lua 库 2018-02-15 13:50:13
-
用于读取 ip2location 地理位置数据库的 Lua 库 2018-02-15 13:36:52