We’ve just released another open-source Node.js module! IPCheck adds an efficient layer on top of ipaddr.js to make it more efficient and seamlessly handle IPv4 and IPv6 addresses.
When passed an IP address and a CIDR block, IPCheck will quickly check whether the IP is in that range.
Check out IPCheck on GitHub or npm.
Detailed usage examples are documented in the README, but here are a few quick examples…
var IPCheck = require('ipcheck');
IPCheck.match('192.168.0.1', '192.168.0.1/32'); //= true
var ip = new IPCheck('FE80:0000:0000:0000:0202:B3FF:FE1E:8329');
var cidr = new IPCheck('FE80:0000:0000:0000:0202:B3FF:FE1E:8329/128');
ip.match(cidr); //= true
ip.match('invalid ip'); //= false
var invalid = new IPCheck(null);
invalid.valid; //= false
Enjoy!