@eryldor/cidr
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

cidr

cidr is a typescript library that helps to manipulate CIDR blocks.

Click here to access the documentation

Usage

import { CIDRBlock } from "@eryldor/cidr";

const cidr = CIDRBlock.fromString("10.0.0.0/16");

//Print "10.0.0.0"
console.log(cidr.networkAddress);
//Print "16"
console.log(cidr.networkPrefix);
//Print "10.0.255.255"
console.log(cidr.broadcastAddress)

//Let's divide it into 2 subnets
const subnets = cidr.split(2);
//Print "10.0.0.0/17"
console.log(subnets[0].toString());
//Print "10.0.128.0/17"
console.log(subnets[1].toString());

//Enumerate all the IPs except the network and broadcast address.
for(ip of cidr.ipAddress()) {
    console.log(ip);
}

Package Sidebar

Install

npm i @eryldor/cidr

Weekly Downloads

351

Version

1.0.5

License

MPL-2.0

Unpacked Size

49.2 kB

Total Files

20

Last publish

Collaborators

  • eryldor