$ luarocks install lua-resty-ipmatcher
-- IPv4, IPv6 and CIDR
local 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"))
ngx.say(ip.match("fe80::1"))