To generate an IP address, we only need to generate a string. The ipv4 ip address data can be generated in the int storage space within the specified range. Let's take a look. to generate an IP address, we only need to generate a string. The ipv4 ip address data can be generated in the int storage space within the specified range. Let's take a look.
Script ec (2); script
Sometimes it is necessary to forge an IP address to capture other website content, preferably a domestic IP address. I found a function on the Internet and can randomly find the domestic IP addresses of 10 IP segments. I checked some IP address data myself, you have manually added 5 IP segments and a total of 15 IP segments, so that you can randomly add many domestic IP addresses, with code:
Function rand_ip (){
$ Ip_long = array (
Array ('100', '100'), // 36.56.0.0-36.63.255.255
Array ('100', '100'), // 58.30.0.0-58.63.255.255
Array ('20140901', '20140901'), // 59.151.0.0-59.151.127.255
Array ('20140901', '20140901'), // 60.194.0.0-60.195.20.255
Array ('20140901', '20140901'), // 61.232.0.0-61.237.255.255
Array ('20140901', '20140901'), // 106.80.0.0-106.95.20.255
Array ('20140901', '20140901'), // 116.13.0.0-116.13.255.255
Array ('20140901', '20140901'), // 118.112.0.0-118.126.255.255
Array ('20140901', '20140901'), // 121.76.0.0-121.77.255.255
Array ('20140901', '20140901'), // 123.232.0.0-123.235.255.255
Array ('-1950089216', '-1948778497'), // 139.196.0.0-139.215.255.255
Array ('-1425539072', '-1425014785'), // 171.8.0.0-171.15.255.255
Array ('-1236271104', '-1235419137'), // 182.80.0.0-182.92.20.255
Array ('-770113536', '-768606209'), // 210.25.0.0-210.47.255.255
Array ('-569376768', '-564133889'), // 222.16.0.0-222.95.20.255
);
$ Rand_key = mt_rand (0, 14 );
$ Huoduan_ip = long2ip (mt_rand ($ ip_long [$ rand_key] [0], $ ip_long [$ rand_key] [1]);
Return $ huoduan_ip;
}
Supplement: long2ip Function
The storage space is reduced to nearly 1/4 (15 bytes of char (15) to 4 bytes of the integer), and it is easier to calculate whether a specific address is in the page of a specific segment, it also speeds up searching and sorting (although sometimes only a little faster ).
Example
$ Ip = long2ip (3232235881 );
Echo $ ip; // 127.20.255