网络划分子网js算法
更新:HHH   时间:2023-1-7


已知一各网络,要求划分为相同大小的子网。

比如已知network:192.168.0.0/23子网,根据要划分的子网块b大小,列出所有子网网络地址:

var network = "192.168.0.0";

var cidr = 23;

var b = 4;//子网块大小此处为变动参数,根据划分的大小

var subnetAmount = Math.pow(2,(32-cidr))/b;//计算子网数量

var p = network.split(".");


for(i=0;i<subnetAmount;i++){

    A = (Number(p[0]) + Math.floor((subnetBlockSize*i)/16777216)%256)%256;

    B = (Number(p[1]) + Math.floor((subnetBlockSize*i)/65536)%256)%256;

    C = (Number(p[2]) + (Math.floor((subnetBlockSize*i)/256)%256)%256)%256;

    D = (Number(p[3]) + (subnetBlockSize*i)%256)%256;

     alert(A+"."+B+"."+C+"."+D);

}


返回开发技术教程...