What is ip-range-check?
The ip-range-check npm package is used to check if an IP address falls within a specified range of IP addresses. It supports both IPv4 and IPv6 addresses and can handle CIDR notation, IP ranges, and individual IP addresses.
What are ip-range-check's main functionalities?
Check if an IP is within a CIDR range
This feature allows you to check if a given IP address falls within a specified CIDR range. In this example, the IP '192.168.1.5' is checked against the CIDR range '192.168.1.0/24'.
const ipRangeCheck = require('ip-range-check');
const ip = '192.168.1.5';
const range = '192.168.1.0/24';
const result = ipRangeCheck(ip, range);
console.log(result); // true
Check if an IP is within a range of IPs
This feature allows you to check if a given IP address falls within a specified range of IP addresses. In this example, the IP '192.168.1.5' is checked against the range ['192.168.1.1', '192.168.1.10'].
const ipRangeCheck = require('ip-range-check');
const ip = '192.168.1.5';
const range = ['192.168.1.1', '192.168.1.10'];
const result = ipRangeCheck(ip, range);
console.log(result); // true
Check if an IP is within multiple ranges
This feature allows you to check if a given IP address falls within any of multiple specified ranges. In this example, the IP '192.168.1.5' is checked against the ranges '192.168.1.0/24' and ['10.0.0.1', '10.0.0.10'].
const ipRangeCheck = require('ip-range-check');
const ip = '192.168.1.5';
const ranges = ['192.168.1.0/24', ['10.0.0.1', '10.0.0.10']];
const result = ipRangeCheck(ip, ranges);
console.log(result); // true
Other packages similar to ip-range-check
ip6
The ip6 package provides utilities for working with IPv6 addresses, including checking if an IP is within a range. It is more specialized for IPv6 compared to ip-range-check, which supports both IPv4 and IPv6.
ip-cidr
The ip-cidr package allows for parsing and manipulation of CIDR notations. It can be used to check if an IP falls within a CIDR range, similar to ip-range-check, but it is more focused on CIDR operations.
range_check
The range_check package provides functions to check if an IP is within a range, supporting both IPv4 and IPv6. It offers similar functionality to ip-range-check but with a different API.
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 = require("ip-range-check");
ipRangeCheck("192.168.1.1", "102.1.5.2/24")
ipRangeCheck("192.168.1.1", "192.168.1.0/24")
ipRangeCheck("192.168.1.1", "192.168.1.1")
ipRangeCheck("192.168.1.1", ["102.1.5.2/24", "192.168.1.0/24", "106.1.180.84"])
ipRangeCheck("195.58.1.62", ["::1/128", "125.92.12.53"])
IPv6
var ipRangeCheck = require("ip-range-check");
ipRangeCheck("::1", "::2/128")
ipRangeCheck("::1", ["::2", "::3/128"])
ipRangeCheck("2001:cdba::3257:9652", "2001:cdba::3257:9652/128")
ipRangeCheck("0:0:0:0:0:FFFF:222.1.41.90", "222.1.41.0/24")
ipRangeCheck("2001:cdba:0000:0000:0000:0000:3257:9652", ["2001:cdba::3257:9652"])
Developing
To run the tests:
npm test