JavaScript traverses all IP in the IP segment

Source: Internet
Author: User

Idea: Convert two IP to a number to compare, the small one slowly add one, until become the big that IP converted number, this one of the number is converted to IP address that is the IP segment all the IP.

1 //IP to Digital2 functionip2int (IP)3 {4     varnum = 0;5ip = Ip.split ("."));6num = number (ip[0]) * * * * * * * * * * * * * * + number (ip[1]) * * * * * * + number (ip[2]) * + + number (ip[3]);7num = num >>> 0;8     returnnum;9 }Ten  One //Digital to IP A functionint2ip (num) - { -     varstr; the     vartt =NewArray (); -TT[0] = (num >>>) >>> 0; -TT[1] = ((num << 8) >>>) >>> 0; -TT[2] = (num << +) >>> 24; +TT[3] = (num <<) >>> 24; -str = string (tt[0]) + "." + string (tt[1]) + "." + string (tt[2]) + "." + String (tt[3]); +     returnstr; A } at  - //list IP in IP segment - functionListip (ip1,ip2) { -     varIpInt1 =Ip2int (ip1); -     varIpInt2 =Ip2int (IP2); -      for(vari = Ipint1;i <= ipint2;i++){ indocument.write (Int2ip (i) + ' <br/> '); to     } + } -  theListip (' 158.66.23.0 ', ' 158.66.23.255 ');

JavaScript traverses all IP in the IP segment

JavaScript traverses all IP in the IP segment

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.