Input:-
ipv4cidr :- String
function u(n) { return n >>> 0; } // we need to treat the numbers as unsigned
function ip(n) {
return [
(n >>> 24) & 0xFF,
(n >>> 16) & 0xFF,
(n >>> 8) & 0xFF,
(n >>> 0) & 0xFF
].join('.');
}
var addr = ipv4cidr,
m = addr.match(/\d+/g), // [ '198', '162', '1', '1', '24' ]
addr32 = m.slice(0, 4).reduce(function (a, o) {
return u(+a << 8) + +o;
}), // 0xc6a20101
mask = u(~0 << (32 - +m[4])); // 0xffffff00
var start = ip(u(addr32 & mask)), // 198.162.1.0
end = ip(u(addr32 | ~mask)); // 198.162.1.
System.log("start: "+start)
System.log("END: "+end)
var ips = []
var start_arr = start.split('.')
System.log("gggg: "+start_arr[start_arr.length-1])
start_arr[3] = Number(start_arr[3])+2
start = start_arr[0]+"."+start_arr[1]+"."+start_arr[2]+"."+Number(start_arr[3]).toString()
ips.push(start);
var end_arr = end.split('.')
System.log("gggg: "+end_arr[end_arr.length-1])
end_arr[3] = end_arr[3]-1
end = end_arr[0]+"."+end_arr[1]+"."+end_arr[2]+"."+Number(end_arr[3]).toString()
ips.push(end);
System.log("start: "+start)
System.log("END: "+end)
return ips;