IP Range Check
This module lets you check if an IP matches one or more IP's or CIDR ranges. It handles IPv6, IPv4, and IPv4-mapped over IPv6 addresses.
It accepts either:
- A single CIDR or IP string, e.g.
"125.19.23.0/24"
, or"2001:cdba::3257:9652"
, or"62.230.58.1"
- An array of CIDR and/or IP strings, e.g.
["125.19.23.0/24", "2001:cdba::3257:9652", "62.230.58.1"]
Importantly, it cannot match an IPv4 address to an IPv6 CIDR or vice versa, (IPv4-mapped IPv6 addresses notwithstanding).
Installing
npm install ip-range-check --save
IPv4
var ipRangeCheck = ; // Checks CIDR// > false// > true // Checks if IP matches string// > true // Checks array of CIDR's and string// > true // Compare IPv6 with IPv4// > false
IPv6
var ipRangeCheck = ; // Handles IPv6 in the same fashion as IPv4// > false// > false// > true // IPv4-mapped IPv6 addresses are automatically converted back to IPv4 addresses// and will match against IPv4 CIDR/IP's.// > true // IPv6 addresses/CIDR's are normalised// > true
Developing
To run the tests:
npm test