SOURCE

var praseIpToBinary = function(ipAddress){
  var numArray = ipAddress.split(".");
  if(numArray.length != 4){
    alert("输入的IP有误");
    return;
  }
  var returnIpStr = "";
  for (var i = 0; i < 4; i++) {
    var curr_num = numArray[i];
    var number_Bin = parseInt(curr_num);
    number_Bin = number_Bin.toString(2);
    var iCount = 8-number_Bin.length;
    for (var j = 0; j < iCount; j++) {
      number_Bin = "0"+number_Bin;
    }
    returnIpStr += number_Bin;
  }
  return returnIpStr;
}

function praseBinaryToIp(binary){
    let res = []
    for(let i=0;i<4;i++){
        let s = binary.substring(i*8,8*(i+1))
        res.push(parseInt(s,2))
    }
    return res.join('.')
}

function getIpArea(iparea){
    let ip = iparea.split('/')[0]
    let num = iparea.split('/')[1]
    ip = praseIpToBinary(ip)
    let start = ip
    let end = ip.substring(0,num)+new Array(parseInt(ip.length-num)).fill(1).join('')
    console.log(end)
    return praseBinaryToIp(start)+ '--' + praseBinaryToIp(end)
}
var ip="10.76.251.0/24";
console.log(getIpArea(ip));
console 命令行工具 X clear

                    
>
console