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

ipv4-calculator

v1.3.1

Published

Calculator for IPv4 networks

Downloads

354

Readme

IPv4 networks calculator

Get IPs list for any network, first network IP address and broadcast IP address.

Installation

npm install ipv4-calculator --save

Usage

import * as ipCalculator from 'ipv4-calculator';

ipCalculator.getNetworkFirstIp('192.210.0.11/30'); // '192.210.0.8'
ipCalculator.getNetworkFirstIpAsArray('192.210.0.11/30'); // [192, 210, 0, 8]
ipCalculator.getNetworkBroadcastIp('192.210.0.25/28'); // '192.210.0.31'
ipCalculator.getNetworkBroadcastIpAsArray('192.210.0.25/28'); // [192, 210, 0, 31]
ipCalculator.getNetworkIps('192.210.0.25/30'); // ['192.210.0.24', '192.210.0.25', '192.210.0.26', '192.210.0.27']
ipCalculator.getNetworkIpsQuantity('192.210.0.25/30'); // 4
ipCalculator.getNetworkIpsQuantityByMask(30); // 4

Other

You are able to use utils, validators and decorators from this package

Utils

import * as utils from 'ipv4-calculator/dist/utils';

utils.numberToBinaryString(2); // '10'
utils.binaryStringToNumber('10'); // 2

utils.ipToBinaryString('192.168.0.29'); // '11000000101010000000000000011101'
utils.binaryStringToIp('11000000101010000000000000011101'); // '192.168.0.29'

utils.ipToNumber('192.168.0.29'); // 3232235549
utils.ipNumberToIp(3232235549); // '192.168.0.29'

utils.ipNumberToBinaryString(3232235549); // '11000000101010000000000000011101'

utils.maskToBinaryString(31); // '11111111111111111111111111111110'
utils.binaryStringToMask('11111111111111111111111111111110'); // 31

Validators

import * as validator from 'ipv4-calculator/dist/validators';

validator.isMaskValid(15); // true
validator.isMaskValid(150); // false

validator.isIpValid('192.169.0.10'); // true
validator.isIpValid('0.0.0.256'); // false

validator.isIpNumberValid(4294967295); // true
validator.isIpNumberValid(4294967295 + 1); // false

validator.isBinaryStringValid('01010101010101010101010101010101'); // true
validator.isBinaryStringValid('22'); // false

validator.isBinaryMaskValid('11111111111111100000000000000000'); // true
validator.isBinaryMaskValid('11111111111111100000000000000001'); // false

validator.isNetworkValid('0.0.0.0/0'); // true
validator.isNetworkValid('0.0.0.0/33'); // false

Decorators

import * as decorators from 'ipv4-calculator/dist/decorators';

class SomeClass {
  @decorators.validateMaskDecorator // throw Error if mask is invalid
  doSomethingWithNetworkMask(mask) {
    // ...
  }

  @decorators.validateIpDecorator // throw Error if IP is invalid
  doSomethingWithIpAddress(ip) {
    // ...
  }

  @decorators.validateNetworkAddressDecorator // throw Error if network is invalid
  doSomethingWithIpNetwork(network) {
    // ...
  }

  @decorators.validateBinaryStringDecorator // throw Error if binary string is invalid
  doSomethingWithBinaryString(string) {
    // ...
  }

  @decorators.validateBinaryMaskDecorator  // throw Error if binary mask is invalid
  doSomethingWithBinaryMask(mask) {
    // ...
  }

  @decorators.validateIpNumberDecorator // throw Error if IP number is invalid
  doSomethingWithIpNumber(ipNumber) {
    // ...
  }
}

// or use decorate util to decorate any function
const myFunc = decorators.decorate(ip => {
  // only if IP valid
  // in other case Error will be throwed
}, decorators.validateIpDecorator);