个性化需求,具体实现代码如下:
/**
* 入参 说明:
domainip 网段范围
popmask 掩码
*
* 出参
* {
"result": 1,
"popips":["11.2.248.0/24","11.2.249.0/24","11.2.250.0/24","11.2.251.0/24","11.2.252.0/24","11.2.253.0/24","11.2.254.0/24","11.2.255.0/24"],
}
*/
function ipsets(domainipmask,popmask) {
let popipsarr = new Array();
if (!domainipmask && !popmask) {
return popipsarr;
}
// 计算域的起始ip地址:
let subnetinfo = ipTool.cidrSubnet(domainipmask);
let flages = true;
var popnetfirstip = subnetinfo.firstAddress;
do {
// 可用地址计算:
var popnetipmask = popnetfirstip + "/" + popmask;
let popinfo = ipTool.cidrSubnet(popnetipmask);
let popfirstip = popinfo.firstAddress;
let poplastip = popinfo.lastAddress;
var firstflagt = ipTool.cidrSubnet(domainipmask).contains(popfirstip);
var lastflagt = ipTool.cidrSubnet(domainipmask).contains(poplastip);
if (firstflagt && lastflagt) {
// 增加到数组中:
popipsarr.push(popnetipmask);
// 下次轮询数据处理:
popnetfirstip = ipTool.fromLong(ipTool.toLong(poplastip) + 2);
} else {
// 跳出循环,网段分配完成:
flages = false;
}
} while (flages);
return popipsarr
}
网友评论