# get-ip-range

> Simple utility to convert either CIDR notation or two IP addresses to an array of the range of IP addresses

Latest version **4.0.1** (published 2021-02-26) · ISC license · 0 weekly downloads

## Install

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

## Health

**Score 25/100 (F)** — status: abandoned.

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.1 |
| Published | 2021-02-26 |
| First published | 2017-09-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.1 KB |
| Known vulnerabilities | 0 (+7 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 11 |
| Author | @JoeScho |
| Maintainers | joescho |
| Keywords | CIDR, IP |

## Links

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

## Dependencies (2)

- [ip](https://npm.io/package/ip.md) ^1.1.5
- [ip-address](https://npm.io/package/ip-address.md) ^6.1.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

- 4.0.1 (latest) — 2021-02-26
- 4.0.0 — 2021-02-10
- 3.0.0 — 2020-10-11
- 2.1.1 — 2020-10-07
- 2.1.0 — 2019-10-22
- 1.1.7 — 2019-02-08
- 1.1.6 — 2019-02-08
- 1.1.5 — 2017-09-01
- 1.1.4 — 2017-09-01
- 1.1.3 — 2017-09-01
- 1.1.2 — 2017-09-01
- 1.1.1 — 2017-09-01
- 1.1.0 — 2017-09-01
- 1.0.0 — 2017-09-01

## README

# get-ip-range
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

Simple utility to convert either CIDR notation, a hyphenated IP range, or two IP addresses to an array of the range of IP addresses.

----

<a href="https://nodei.co/npm/get-ip-range/"><img src="https://nodei.co/npm/get-ip-range.png?downloads=true"></a>

![Build Status](https://travis-ci.org/JoeScho/get-ip-range.svg?branch=main)[![ISC License](https://img.shields.io/badge/license-ISC-blue.svg?style=flat-square)](https://github.com/JoeScho/getIPRange/blob/main/LICENSE)

----

## Installation

```sh
$ npm i get-ip-range
```

----

## Accepted formats
### IPv4
* CIDR `"x.x.x.x/x"`
* Range `"x.x.x.x-x.x.x.x"`
* Two IPs `"x.x.x.x", "x.x.x.x"`

### IPv6
* CIDR `"x:x:x:x:x:x:x:x/x"`
* Range `"::x:x:x-::x:x:x"`
* Two IPs `"::x:x:x", "::x:x:x"`

**N.B. Shorthand IPv6 is supported**

----

## Usage
```ts
import { getIPRange } from 'get-ip-range';

const ipv4CIDR = getIPRange('192.168.1.134/29');
const ipv4Range = getIPRange('192.168.1.128-192.168.1.135');
const twoIPv4 = getIPRange('192.168.1.128', '192.168.1.135');

// All return:
[
  '192.168.1.128',
  '192.168.1.129',
  '192.168.1.130',
  '192.168.1.131',
  '192.168.1.132',
  '192.168.1.133',
  '192.168.1.134',
  '192.168.1.135',
]

const ipv6CIDR = getIPRange('0:0:0:0:0:ffff:102:304/126');
const ipv6Range = getIPRange('::ffff:102:304-::ffff:102:307');
const twoIPv6 = getIPRange('::ffff:102:304', '::ffff:102:307');

// All return:
[
  '::ffff:102:304',
  '::ffff:102:305',
  '::ffff:102:306',
  '::ffff:102:307',
]
```

----

**Errors**

* If the supplied IP address(es) are invalid, the request will **throw an [error](https://nodejs.org/api/errors.html#errors_class_error)**. Please handle errors appropriately.
* If there are more than the default maximum range (10000) or the environment variable (MAX_RANGE) IPs in the range, it will throw an error.

----

## Contributors
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
  <tr>
    <td align="center"><a href="https://github.com/JoeScho"><img src="https://avatars.githubusercontent.com/u/12475501?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Joe Schofield</b></sub></a><br /><a href="https://github.com/JoeScho/get-ip-range/commits?author=JoeScho" title="Code">💻</a></td>
    <td align="center"><a href="https://github.com/Miosame"><img src="https://avatars.githubusercontent.com/u/8201077?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Miosame</b></sub></a><br /><a href="https://github.com/JoeScho/get-ip-range/commits?author=Miosame" title="Code">💻</a></td>
    <td align="center"><a href="https://github.com/JGAntunes"><img src="https://avatars.githubusercontent.com/u/5799039?v=4?s=100" width="100px;" alt=""/><br /><sub><b>João Antunes</b></sub></a><br /><a href="https://github.com/JoeScho/get-ip-range/commits?author=JGAntunes" title="Code">💻</a></td>
    <td align="center"><a href="https://github.com/ch-t"><img src="https://avatars.githubusercontent.com/u/26768691?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Chingiz Toimbetov</b></sub></a><br /><a href="https://github.com/JoeScho/get-ip-range/commits?author=ch-t" title="Code">💻</a></td>
    <td align="center"><a href="https://github.com/yaniv-checkmarx"><img src="https://avatars.githubusercontent.com/u/59412524?v=4?s=100" width="100px;" alt=""/><br /><sub><b>yaniv-checkmarx</b></sub></a><br /><a href="https://github.com/JoeScho/get-ip-range/issues?q=author%3Ayaniv-checkmarx" title="Bug reports">🐛</a></td>
    <td align="center"><a href="https://github.com/stasizon"><img src="https://avatars.githubusercontent.com/u/7525031?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Stanislav Sizonenko</b></sub></a><br /><a href="https://github.com/JoeScho/get-ip-range/issues?q=author%3Astasizon" title="Bug reports">🐛</a></td>
  </tr>
</table>

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

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