Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/brh55/min-prefix-length

:1234: Calculate the minimum prefix length for an IPv4 subnet based on a desired number of host
https://github.com/brh55/min-prefix-length

ipv4 networking subnet

Last synced: 30 days ago
JSON representation

:1234: Calculate the minimum prefix length for an IPv4 subnet based on a desired number of host

Awesome Lists containing this project

README

        

# min-prefix-length [![Build Status](https://img.shields.io/travis/brh55/min-prefix-length.svg?style=flat-square)](https://travis-ci.org/brh55/min-prefix-length) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg?style=flat-square)](https://github.com/sindresorhus/xo)

> Calculate the minimum prefix length for an IPv4 subnet based on a desired number of host accounting for broadcast and network addresses
>
> **minPrefixLength(8) => 28**

## Install

```
$ npm install --save min-prefix-length
```

## Usage

```js
const minPrefixLength = require('min-prefix-length');

const prefix = minPrefixLength(28);
const CIDR = `192.168.1.0/${prefix}`
console.log(CIDR)
// => "192.168.1.0/28"
```

## API

### minPrefixLength(n)

Returns the minimum prefix length needed to support *n* of hosts accounting for the network and broadcast address

#### n | ``

*n* number of desired hosts

## Related
[min-host-bits](https://github.com/brh55/min-host-bits) - :computer: Calculate minimum host bits needed for desired number of hosts

[ip-class](https://github.com/brh55/ip-class) - :capital_abcd: Return the classful network class (A, B, C, D, E) of an IPv4 address

## License

MIT © [Brandon Him](https://github.com/brh55)