# ip-range-check

> Check whether an IP(v4 or v6) is in an CIDR range

Latest version **0.2.1** (published 2026-08-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install ip-range-check
pnpm add ip-range-check
yarn add ip-range-check
bun add ip-range-check
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2026-08-05 |
| First published | 2015-06-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 80 |
| Author | Daniel Compton |
| Maintainers | danielcompton |
| Keywords | ip, ipv6, IP, Address, CIDR, range |

## Links

- npm: https://www.npmjs.com/package/ip-range-check
- Repository: https://github.com/danielcompton/ip-range-check
- Homepage: https://github.com/danielcompton/ip-range-check#readme
- Issues: https://github.com/danielcompton/ip-range-check/issues
- npm.io page: https://npm.io/package/ip-range-check

## Dependencies (1)

- [ipaddr.js](https://npm.io/package/ipaddr.js.md) ^2.5.0

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 0.2.1 (latest) — 2026-08-05
- 0.2.0 — 2019-06-21
- 0.0.2 — 2016-09-05
- 0.0.1 — 2015-06-10

## README

# IP Range Check

[![Test](https://github.com/danielcompton/ip-range-check/actions/workflows/test.yml/badge.svg)](https://github.com/danielcompton/ip-range-check/actions/workflows/test.yml)

[![NPM](https://nodei.co/npm/ip-range-check.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/ip-range-check)

This module lets you check if an IP matches one or more IP's or [CIDR](http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) 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

```sh
npm install ip-range-check --save
```

## IPv4

```js
var ipRangeCheck = require("ip-range-check");

// Checks CIDR
ipRangeCheck("192.168.1.1", "102.1.5.2/24")
// > false
ipRangeCheck("192.168.1.1", "192.168.1.0/24")
// > true

// Checks if IP matches string
ipRangeCheck("192.168.1.1", "192.168.1.1")
// > true

// Checks array of CIDR's and string
ipRangeCheck("192.168.1.1", ["102.1.5.2/24", "192.168.1.0/24", "106.1.180.84"])
// > true

// Compare IPv6 with IPv4
ipRangeCheck("195.58.1.62", ["::1/128", "125.92.12.53"])
// > false

```

## IPv6

```js
var ipRangeCheck = require("ip-range-check");

// Handles IPv6 in the same fashion as IPv4
ipRangeCheck("::1", "::2/128")
// > false
ipRangeCheck("::1", ["::2", "::3/128"])
// > false
ipRangeCheck("2001:cdba::3257:9652", "2001:cdba::3257:9652/128")
// > true

// IPv4-mapped IPv6 addresses are automatically converted back to IPv4 addresses
// and will match against IPv4 CIDR/IP's.
ipRangeCheck("0:0:0:0:0:FFFF:222.1.41.90", "222.1.41.0/24")
// > true

// IPv6 addresses/CIDR's are normalised
ipRangeCheck("2001:cdba:0000:0000:0000:0000:3257:9652", ["2001:cdba::3257:9652"])
// > true
```

## Developing

To run the tests (requires Node.js 22 or newer, which provides the built-in
test runner):

```
npm test
```

---
_Source: https://npm.io/package/ip-range-check · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
