npm install ip-cidr
Module for working with CIDR (v4, v6). Based on ip-address
const CIDR = require("ip-cidr");
let cidr = new CIDR("50.165.190.0/23");
if(!cidr.isValid()) {
// something
}
cidr.start(); // get start ip as string
cidr.end({ asBigInteger: true }); // get end ip as big integer
let data = [];
let fn = (ip) => {
// do something with each element of CIDR range
data.push(ip) // ip is "ip-address" module object, because of option asAddressObject is true
}
cidr.arrayAction(fn, { asAddressObject: true });
cidr.toArray({ asBigInteger: true }); // get array of all ip in CIDR range as big integer;
cidr.toRange(); // get array of start and end ip as string [startIpAsString, endIpAsString]returns the "ip-address" module object in the necessary format
options are the same in all of the library functions and might include asBigInteger, asAddressObject or asString (by default)
get start ip
get end ip
get string cidr as "50.165.190.0/23"
get array of start and end ip [startIp, endIp]
get object of start and end ip {start: startIp, end: endIp}
get array of all ip in CIDR range
you can get information by chunks using options.from and options.limit
this options might be integer or big integer("jsbn" instance)
you can pass second argument "results" (object) to get all chunk pagination information
run fn for every element of CIDR range
you can use the same chunk options as in .toArray