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