在下面的代码中,ipClassRangeTop[3] = ipClassRangeBottom[3] + subNetCount - 1; 似乎 subNetCount 也被添加到 ipClassRangeBottom[3] 中。这不是我所期待的结果。我只希望 ipClassRangeTop[3] 具有该值。
有人可以让我知道我可能做错了什么。我对任何类型的编码都很陌生,因此非常感谢任何帮助。
var ipAddress = "172.16.1.1";
var subNetCount = 1 << 6;
var ipClassRangeTop = new Array();
var ipClassRangeBottom = new Array();
var classMaskDec = 65536;
var loopCount = 3; //classMaskDec/subNetCount;
//console.log(ipAddress, "ip address");
ipAddress = ipAddress.split(".");
ipClassRangeBottom = ipAddress;
ipClassRangeBottom[2] = 0;
ipClassRangeBottom[3] = 0;
ipClassRangeTop = ipClassRangeBottom;
//console.log(ipAddress, "ip address");
while (loopCount > 0 ) {
//console.log(i++);
console.log(ipClassRangeBottom, "1st bottom in loop");
ipClassRangeTop[3] = ipClassRangeBottom[3] + subNetCount - 1;
console.log(ipClassRangeBottom, "after top [3] assign");
if (ipClassRangeTop[3] > 255) {
ipClassRangeTop[2] = ipClassRangeTop[2] + 1;
ipClassRangeTop[3] = subNetCount - 1;
console.log("IF RAN");
}
console.log(loopCount);
console.log(ipClassRangeTop);
console.log(ipClassRangeBottom);
ipClassRangeBottom[3] = ipClassRangeBottom[3] + subNetCount;
console.log(ipClassRangeBottom);
loopCount--;
}
console.log(ipAddress, "ip address");
console.log(ipClassRangeTop);
console.log(ipClassRangeBottom);
谢谢,马克