JS algorithm of network partition subnet

Source: Internet
Author: User

It is known that a network is required to be divided into subnets of the same size.

For example, a known NETWORK:192.168.0.0/23 subnet, which lists all the subnet network addresses according to the subnet block B size to be divided:

var network = "192.168.0.0";

var CIDR = 23;

var B = 4;//Subnet block size here for the change parameter, depending on the size of the partition

var subnetamount = Math.pow (2, (32-CIDR))/b;//count subnets

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);

}


JS algorithm of network partition subnet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.