Php randomly generates domestic IP addresses-PHP source code

Source: Internet
Author: User
Php randomly generates a domestic ip address to obtain all ip segments in a country, and randomly generates a shrinking domestic ip address.
Note: the last five values in the $ ip_long array may be incorrect in 64-bit systems (in the code below, the last five values in the $ ip_long array are negative in 32-bit systems, the value is positive in 64-bit systems. the first five values may also be incorrect in 64-bit systems)
32-bit system
Echo ip2long ("172.16.1.63 ″);
Result: 1408237249
64-bit operating system
Echo ip2long ("172.16.1.63 ″);

Download all IP address segments
Http://www.ipaddresslocation.org/ip_ranges/get_ranges.php

Randomly generate domestic IP addresses due to shrinking
There are more than 1600 CIDR blocks in total, and only 10 of them are determined to be domestic CIDR blocks.
Two php functions are used.
Ip2long ($ ip) converts ip to int
Long2ip ($ int_ip) converts int back to ip

 

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.