npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-ipv4

v1.1.2

Published

A package to calculate subnet masks.

Downloads

134

Readme

IPv4 Parser

Generated by OSS Project Generator.

Travis Status AppVeyor Status CircleCI Status Coveralls Status NPM Version License

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:

# Install globally
$ npm install -g node-ipv4

# Check installation
$ node-ipv4 --version

To install locally:

$ npm install node-ipv4

Usage

There are two ways to use node-ipv4: globally and locally.

Globally

  • -V or --version: output the version number

$ node-ipv4 --version
1.1.2
  • -h or --help: output usage information

$ node-ipv4 --help

  Usage: 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

# 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

const ipv4 = require('node-ipv4');

ipv4.parse('192.168.1.1', 16, (err, subnet) => {
  if (err) return console.error(err);

  console.log(subnet);
});

Output

{
  "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
$ git clone https://github.com/robertoachar/node-ipv4.git
  • Install dependencies
$ 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

License

MIT