Quickly parses IP addresses, allowing them to be checked for CIDR matches.
Converts IPv4 to IPv6 to keep the process seamless and allow transitional IPs.
npm install ipcheck --save
To easily check an IP and a CIDR without any extra thrills...
varIPCheck=require('ipcheck');IPCheck.match('192.168.0.1','192.168.0.1/32');//= trueAllows you to individually validate and re-use different IPs.
varIPCheck=require('ipcheck');varip=newIPCheck('192.168.0.1');varcidr=newIPCheck('192.168.0.1/32');ip.match(cidr);//= trueWorks seamlessly!
IPCheck.match('FE80:0000:0000:0000:0202:B3FF:FE1E:8329','FE80:0000:0000:0000:0202:B3FF:FE1E:8329/128');//= trueAs all IPv4 addresses are converted to IPv6, transitional IPs are supported.
varip=newIPCheck('192.168.0.1');varipv4cidr=newIPCheck('192.168.0.1/32');varipv6cidr=newIPCheck('::ffff:192.168.0.1/128');ip.match(ipv4cidr);//= trueip.match(ipv6cidr);//= trueTo convert a CIDR from IPv4 to IPv6, the mask simply has 96 added to it.
IPCheck is designed to not throw errors.
If you'd like to know an address is valid, simply read the valid property...
varip=newIPCheck('192.168.0.1');ip.valid;//= truevarbadIP=newIPCheck(['huh?']);badIP.valid;//= falsevaranotherBadIP=newIPCheck('silly.ip');anotherBadIP.valid;//= false// Match always returns false if either the IP or the CIDR are invalidIPCheck.match('hi','oh/no');npm run benchmark - simply compares this to ipaddr.js and ip-address modules in places. The TL;DR of it is that ipcheck is reliably faster.
npm test - ensure everything works!
