Skip to content
A simple and very fast function to check against CIDR
Perl Lua Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib/resty
t
util
.travis.yml
Makefile
README.md
dist.ini

README.md

lua-resty-ipcidr Build Status

A simple and very fast function to check against CIDR

Overview

access_by_lua_block {
    local ipcidr = require("resty.ipcidr")
    local whitelist_ips = {
      "127.0.0.1",
      "10.10.10.0/24",
      "192.168.0.0/16",
  }
    if not ipcidr.ip_in_cidrs(ngx.var.remote_addr, whitelist_ips) then
      return ngx.exit(ngx.HTTP_FORBIDDEN)
    end
}

Methods

ip_in_cidrs

syntax: bool, err = ipcidr.ip_in_cidrs(ip, cidrs)

Takes a string IPv4 address and a table of parsed CIDRs.

Returns a true or false if the IP exists within any of the specified networks.

Returns nil and an error message with an invalid IP

You can’t perform that action at this time.