Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/brh55/min-prefix-length
- Owner: brh55
- License: mit
- Created: 2017-01-27T18:55:07.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-02T00:00:16.000Z (almost 8 years ago)
- Last Synced: 2024-08-08T22:36:50.742Z (3 months ago)
- Topics: ipv4, networking, subnet
- Language: JavaScript
- Homepage:
- Size: 36.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
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)