开源软件名称(OpenSource Name):api7/lua-resty-ipmatcher开源软件地址(OpenSource Url):https://github.com/api7/lua-resty-ipmatcher开源编程语言(OpenSource Language):Lua 54.3%开源软件介绍(OpenSource Introduction):lua-resty-ipmatcherHigh performance match IP address for OpenResty Lua. APIlocal ipmatcher = require("resty.ipmatcher")
local ip = ipmatcher.new({
"127.0.0.1",
"192.168.0.0/16",
"::1",
"fe80::/32",
})
ngx.say(ip:match("127.0.0.1"))
ngx.say(ip:match("192.168.1.100"))
ngx.say(ip:match("::1")) ipmatcher.new
The local ip, err = ipmatcher.new({"127.0.0.1", "192.168.0.0/16"}) Returns It supports any CIDR format for IPv4 and IPv6. local ip, err = ipmatcher.new({
"127.0.0.1", "192.168.0.0/16",
"::1", "fe80::/16",
}) ipmatcher.new_with_value
The When the local ip, err = ipmatcher.new_with_value({
["127.0.0.1"] = {info = "a"},
["192.168.0.0/16"] = {info = "b"},
})
local data, err = ip:match("192.168.0.1")
print(data.info) -- the value is "b" Returns It supports any CIDR format for IPv4 and IPv6. local ip, err = ipmatcher.new_with_value({
["127.0.0.1"] = {info = "a"},
["192.168.0.0/16"] = {info = "b"},
["::1"] = 1,
["fe80::/32"] = "xx",
}) If the ip address can be satified by multiple CIDR ranges, the returned value is undefined (depended on the internal implementation). For instance, local ip, err = ipmatcher.new_with_value({
["192.168.0.1"] = {info = "a"},
["192.168.0.0/16"] = {info = "b"},
})
local data, err = ip:match("192.168.0.1")
print(data.info) -- the value can be "a" or "b" ip.match
Returns a local ok, err = ip:match("127.0.0.1") ip.match_bin
Returns a Returns local ok, err = ip:match_bin(ngx.var.binary_remote_addr) ipmatcher.parse_ipv4
Tries to parse an IPv4 address to a host byte order FFI uint32_t type integer. Returns a ipmatcher.parse_ipv6
Tries to parse an IPv6 address to a table with four host byte order FFI uint32_t
type integer. The given IPv6 address can be wrapped by square brackets
like Returns a |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论