# netaddr

> Utility for IP addresses and CIDR expressions

Latest version **1.1.0** (published 2015-08-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install netaddr
pnpm add netaddr
yarn add netaddr
bun add netaddr
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2015-08-24 |
| First published | 2015-08-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | d11wtq |
| Maintainers | d11wtq |
| Keywords | ip, ipv4, cidr, subnet |

## Links

- npm: https://www.npmjs.com/package/netaddr
- Repository: https://github.com/d11wtq/netip
- Issues: https://github.com/d11wtq/netip/issues
- npm.io page: https://npm.io/package/netaddr

## 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

- 1.1.0 (latest) — 2015-08-24
- 1.0.1 — 2015-08-24
- 1.0.0 — 2015-08-24
- 0.1.0 — 2015-08-23

## README

# netaddr.js

Node.js utility package for working with IP addresses and CIDR ranges.

## Installation

```
$ npm install netaddr --save
```

## Usage

``` javascript
var Addr = require('netaddr').Addr;

// Create a fixed IP address from a string
var localhost = Addr('127.0.0.1');

// Create  CIDR range from a string
var subnet = Addr('10.0.0.0/16');

// Create a CIDR range from an integer and prefix
var subnet = Addr(167772160, 16);

// Convert an IP address to an integer
var intval = Addr('127.0.0.1').toInt();

// Get the network address
var network = subnet.network();

// Get the broadcast address
var broadcast = subnet.broadcast();

// Mask the address with a new prefix
var masked = subnet.mask(24);

// Check if one CIDR contains another CIDR or IP
subnet.contains(Addr('10.0.3.0/24')); // true

// Check where two CIDRs intersect
subnet.intersect(Addr('10.0.3.0/24'));

// Increment an address (non-mutating)
localhost.increment();

// Decrement an address (non-mutating)
localhost.decrement();

// Find the next adjacent subnet
subnet.nextSibling();

// Find the previous adjacent subnet
subnet.prevSibling();
```

Attempts to create an invalid `Addr` will throw an `Error`.

## Limitations

Currently only IPv4 is supported, though there are plans to add IPv6 support.
This is complicated by the fact JavaScript does not support 64-bit integers,
let alone 128-bit integers.

## Copyright & License

Copyright © 2015 Chris Corbyn. See the LICENSE file for details.

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