Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/robertoachar/node-ipv4
A package to calculate subnet masks.
https://github.com/robertoachar/node-ipv4
cidr ip ipv4 network node npm subnet
Last synced: 11 days ago
JSON representation
A package to calculate subnet masks.
- Host: GitHub
- URL: https://github.com/robertoachar/node-ipv4
- Owner: robertoachar
- License: mit
- Created: 2016-09-29T20:55:41.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-18T18:42:35.000Z (over 6 years ago)
- Last Synced: 2024-10-29T11:12:30.720Z (19 days ago)
- Topics: cidr, ip, ipv4, network, node, npm, subnet
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/node-ipv4
- Size: 106 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# IPv4 Parser
Generated by [OSS Project Generator](http://bit.ly/generator-oss-project).
[![Travis Status][travis-badge]][travis-url]
[![AppVeyor Status][appveyor-badge]][appveyor-url]
[![CircleCI Status][circleci-badge]][circleci-url]
[![Coveralls Status][coveralls-badge]][coveralls-url]
[![NPM Version][npm-badge]][npm-url]
[![License][license-badge]][license-url]> A package to calculate subnet masks.
This package provides the following features:
* Allows you to parse an IPv4 address
* Provides the address, size, netmask, first and last addresses.
* Each address provides decimal, binary and hexadecimal values.# Installation
There are two ways to install `node-ipv4`: globally and locally.
To install globally:
```bash
# Install globally
$ npm install -g node-ipv4# Check installation
$ node-ipv4 --version
```To install locally:
```bash
$ npm install node-ipv4
```# Usage
There are two ways to use `node-ipv4`: globally and locally.
## Globally
* ### `-V` or `--version`: output the version number
```bash
$ node-ipv4 --version
1.1.2
```* ### `-h` or `--help`: output usage information
```bash
$ node-ipv4 --helpUsage: cli [options]
Options:
-h, --help output usage information
-V, --version output the version number
-i, --ip [ip] IP Address
-c, --cidr [cidr] Cdir block
```* ### `-i` or `--ip [ip: string]`: enter the IP address
* ### `-c` or `--cidr [ip: number]`: enter the CIDR block```bash
# without alias
$ node-ipv4 --ip 192.168.1.1 --cidr 8# with alias
$ node-ipv4 -i 192.168.1.1 -c 8# output
{
"cidr": 8,
"size": 16777216,
"address": {
"value": 3232235777,
"address": "192.168.1.1",
"binary": "11000000101010000000000100000001",
"hexadecimal": "C0A80101"
},
"netmask": {
"value": 4278190080,
"address": "255.0.0.0",
"binary": "11111111000000000000000000000000",
"hexadecimal": "FF000000"
},
"first": {
"value": 3221225472,
"address": "192.0.0.0",
"binary": "11000000000000000000000000000000",
"hexadecimal": "C0000000"
},
"last": {
"value": 3238002687,
"address": "192.255.255.255",
"binary": "11000000111111111111111111111111",
"hexadecimal": "C0FFFFFF"
}
}
```## Locally
```javascript
const ipv4 = require('node-ipv4');ipv4.parse('192.168.1.1', 16, (err, subnet) => {
if (err) return console.error(err);console.log(subnet);
});
```## Output
```json
{
"cidr": 16,
"size": 65536,
"address": {
"value": 3232235777,
"address": "192.168.1.1",
"binary": "11000000101010000000000100000001",
"hexadecimal": "C0A80101"
},
"netmask": {
"value": 4294901760,
"address": "255.255.0.0",
"binary": "11111111111111110000000000000000",
"hexadecimal": "FFFF0000"
},
"first": {
"value": 3232235520,
"address": "192.168.0.0",
"binary": "11000000101010000000000000000000",
"hexadecimal": "C0A80000"
},
"last": {
"value": 3232301055,
"address": "192.168.255.255",
"binary": "11000000101010001111111111111111",
"hexadecimal": "C0A8FFFF"
}
}
```# Documentation
## Address
* `value`: {Number} Decimal value of an address
* `address`: {String} String value of an address
* `binary`: {String} Binary value of an address
* `hexadecimal`: {String} Hexadecimal value of an address## IPv4
* `cidr`: {Number} CIDR block
* `size`: {Number} Size of subnet
* `address`: {Object:Address} The input address
* `netmask`: {Object:Address} The subnet mask
* `first`: {Object:Address} The first address
* `last`: {Object:Address} The last address## API: parse(address, cidr, callback)
* `address` {String} IP address
* `cidr` {Number} CIDR block
* `callback` {Function}
* `err` {Error | null} Error
* `ipv4` {Object:IPv4} Instance of `IPv4`# Development
* Clone the repo
```bash
$ git clone https://github.com/robertoachar/node-ipv4.git
```* Install dependencies
```bash
$ npm install
```* Running scripts
| Action | Usage |
| ---------------------------------------- | ------------------- |
| Linting code | `npm run lint` |
| Running unit tests | `npm run jest` |
| Running code coverage | `npm run coverage` |
| Running lint + tests | `npm test` |
| Sending coverage results to Coveralls.io | `npm run coveralls` |# Author
[Roberto Achar](https://twitter.com/RobertoAchar)
# License
[MIT](https://github.com/robertoachar/node-ipv4/blob/master/LICENSE)
[travis-badge]: https://travis-ci.org/robertoachar/node-ipv4.svg?branch=master
[travis-url]: https://travis-ci.org/robertoachar/node-ipv4
[appveyor-badge]: https://ci.appveyor.com/api/projects/status/github/robertoachar/node-ipv4?branch=master&svg=true
[appveyor-url]: https://ci.appveyor.com/project/robertoachar/node-ipv4
[circleci-badge]: https://circleci.com/gh/robertoachar/node-ipv4/tree/master.svg?style=shield
[circleci-url]: https://circleci.com/gh/robertoachar/node-ipv4
[coveralls-badge]: https://coveralls.io/repos/github/robertoachar/node-ipv4/badge.svg?branch=master
[coveralls-url]: https://coveralls.io/github/robertoachar/node-ipv4?branch=master
[npm-badge]: https://img.shields.io/npm/v/node-ipv4.svg
[npm-url]: https://www.npmjs.com/package/node-ipv4
[license-badge]: https://img.shields.io/github/license/robertoachar/node-ipv4.svg
[license-url]: https://opensource.org/licenses/MIT