The IPv4 CIDR in string, object, or tuple format.
A new Ipv4Cidr instance.
import { ipv4 } from 'cidr-block';
const cidr1 = ipv4.cidr("192.168.0.0/24");
const cidr2 = ipv4.cidr({ address: "10.0.0.0", range: 8 });
const cidr3 = ipv4.cidr([[172, 16, 0, 0], 12]);
import { ipv4 } from 'cidr-block';
const cidr = ipv4.cidr("192.168.0.0/24");
cidr.baseAddress().toString(); // "192.168.0.0"
cidr.range(); // 24
cidr.netmask().toString(); // "255.255.255.0"
cidr.addressCount(); // 256
import { ipv4 } from 'cidr-block';
const cidr = ipv4.cidr("192.168.0.0/24");
cidr.getFirstUsableAddress()?.toString(); // "192.168.0.1"
cidr.getLastUsableAddress()?.toString(); // "192.168.0.254"
import { ipv4 } from 'cidr-block';
const cidr = ipv4.cidr("192.168.1.0/30");
for (const addr of cidr.addresses()) {
console.log(addr.toString());
}
// "192.168.1.0", "192.168.1.1", "192.168.1.2", "192.168.1.3"
import { ipv4 } from 'cidr-block';
const cidr = ipv4.cidr("192.168.0.0/24");
cidr.includes(ipv4.address("192.168.0.100")); // true
cidr.includes(ipv4.address("192.168.1.1")); // false
cidr.overlaps("192.168.0.0/25"); // true
cidr.overlaps("10.0.0.0/8"); // false
import { ipv4 } from 'cidr-block';
const cidr = ipv4.cidr("192.168.0.0/24");
// Split into equal /26 subnets
cidr.subnet(26).map(s => s.toString());
// ["192.168.0.0/26", "192.168.0.64/26", "192.168.0.128/26", "192.168.0.192/26"]
// Split by specific ranges
cidr.subnetBy([25, 26, 27, 27]).map(s => s.toString());
// ["192.168.0.0/25", "192.168.0.128/26", "192.168.0.192/27", "192.168.0.224/27"]
Creates a new Ipv4Cidr instance from the given literal. Valid formats include string, object, or tuple.