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 🙏

© 2026 – Pkg Stats / Ryan Hefner

vlsmcalc

v2.0.1

Published

Lib to calc Variable Length Subnet Masking

Readme

vlsmcalc

npm version npm downloads Coverage License GitHub release PRs Welcome

vlsmcalc is a library designed for network administrators and developers to easily calculate Variable Length Subnet Masking (VLSM). It helps you generate optimized subnets for a given major network, considering specific host requirements for each subnet.


Table of Contents

  1. Features
  2. Prerequisites
  3. Installation
  4. Usage
  5. Examples
  6. Contributing
  7. License

Features

  • Dynamically calculates subnets based on host requirements for each subnet.
  • Computes subnet masks, network addresses, broadcast addresses, and the first and last usable IPs.
  • Validates input major networks and ensures subnet creation is possible.
  • Efficient subnetting: Optimizes network allocation by calculating the smallest subnet mask that fits the host requirements for each subnet, reducing IP wastage.
  • Scalability: Supports creating subnets for networks with large IP space and varying host requirements, making it suitable for both small and large networks.
  • Validation: Automatically checks for errors in input, such as insufficient IP space or invalid CIDR notation.

Prerequisites

Before using vlsmcalc, ensure that you have:

  • Node.js (version 12 or higher) installed. Download Node.js
  • A package manager such as npm or yarn:

Installation

To install the library, you can use Yarn or npm:

Using Yarn:

yarn add vlsmcalc

Using npm:

npm install vlsmcalc

Local Development Setup

To get started with local development, follow these steps:

  1. Clone the repository:
git clone https://github.com/yourusername/project-name.git
  1. Install the project dependencies:
yarn install
  1. Run the tests:
yarn test

Usage

Here's an example of how to use vlsmcalc:

const Subnet = require('vlsmcalc');

// Define the major network and hosts per subnet
const majorNetwork = '192.168.1.0/24'; 
const hostsEachSubnet = [50, 20, 10]; 

// Instantiate the Subnet class with host requirements and major network
const subnetCalc = new Subnet(hostsEachSubnet, majorNetwork);

// Validate if subnetting is possible
if (subnetCalc.isValid()) {
    const networks = subnetCalc.getNetworks();
    networks.forEach((network, index) => {
        console.log(`Subnet ${index + 1}:`);
        console.log(`  Network Address: ${network.getNetwork()}`);
        console.log(`  Subnet Mask: ${network.getSubnetMask()}`);
        console.log(`  Broadcast Address: ${network.getBroadcast()}`);
        console.log(`  First Usable IP: ${network.getFirstIP()}`);
        console.log(`  Last Usable IP: ${network.getLastIP()}`);
        console.log(`  Prefix: /${network.getPrefix()}`);
        console.log(`  Allocated Size: ${network.getAllocatedSize()} hosts`);
    });
} else {
    console.log('Invalid major network or insufficient space for requested subnets.');
}

Error Handling

For improved reliability, you can include error handling to catch invalid inputs or unexpected issues:

try {
    if (subnetCalc.isValid()) {
        const networks = subnetCalc.getNetworks();
        // Continue as above...
    } else {
        console.log('Invalid major network or insufficient space for requested subnets.');
    }
} catch (error) {
    console.error('Error during subnet calculation:', error);
}

Examples

Subnetting Example

const VLSMCalc = require('vlsmcalc');

let hostsEachSubnet = [500, 250, 100, 50];  // Hosts required for each subnet
let majorNetwork = '192.168.0.0/24';        // Major network in CIDR notation

// Create subnet calculation
let subnet = new VLSMCalc(hostsEachSubnet, majorNetwork);

// Get networks (subnets)
let networks = subnet.getNetworks();

// Output network details
networks.forEach(network => {
    console.log(`Network: ${network.getNetwork()}`);
    console.log(`Subnet Mask: ${network.getSubnetMask()}`);
    console.log(`First IP: ${network.getFirstIP()}`);
    console.log(`Last IP: ${network.getLastIP()}`);
    console.log(`Broadcast: ${network.getBroadcast()}`);
    console.log(`---------------------------------`);
});

Expected Output:

Network: 192.168.0.0
Subnet Mask: 255.255.255.0
First IP: 192.168.0.1
Last IP: 192.168.0.254
Broadcast: 192.168.0.255
---------------------------------
Network: 192.168.1.0
Subnet Mask: 255.255.255.128
First IP: 192.168.1.1
Last IP: 192.168.1.126
Broadcast: 192.168.1.127
---------------------------------
Network: 192.168.1.128
Subnet Mask: 255.255.255.192
First IP: 192.168.1.129
Last IP: 192.168.1.190
Broadcast: 192.168.1.191
---------------------------------
Network: 192.168.1.192
Subnet Mask: 255.255.255.224
First IP: 192.168.1.193
Last IP: 192.168.1.222
Broadcast: 192.168.1.223
---------------------------------

Calculating Next Network

const { Network } = require('vlsmcalc');

let majorNetwork = '192.168.0.0/24';
let network = new Network(500, majorNetwork);

// Get the next available network after allocation
console.log('Next Network:', network.getNextNetwork());
Next Network: 192.168.1.0

Contributing

We welcome contributions to this project! If you find any issues or have improvements to suggest, feel free to open an issue or submit a pull request.

Before you contribute, please ensure you check the existing issues to avoid duplicates.

To contribute, follow these steps:

  1. Fork the repository.
  2. Clone your fork to your local machine.
  3. Create a new branch for your changes.
  4. Make your changes and add tests if applicable.
  5. Run the tests to ensure everything works:
    yarn test
  6. Create a pull request with a description of your changes.

Your contributions help improve this project, and we appreciate your effort!

Repository

Find the source code and report issues at: GitHub Repository.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author

Created by Marco De Araujo. For more details, visit marcodearaujo.com or connect with me on LinkedIn.