本人是asp程序員,這是首次寫php程序,一點心得發上來共享
復制代碼 代碼如下:
<?php
$ip2id= round(rand(600000, 2550000) / 10000); //第一種方法,直接生成
$ip3id= round(rand(600000, 2550000) / 10000);
$ip4id= round(rand(600000, 2550000) / 10000);
//下面是第二種方法,在以下數據中隨機抽取
$arr_1 = array("218","218","66","66","218","218","60","60","202","204","66","66","66","59","61","60","222","221","66","59","60","60","66","218","218","62","63","64","66","66","122","211");
$randarr= mt_rand(0,count($arr_1)-1);
$ip1id = $arr_1[$randarr];
echo $ip1id;
echo ".";
echo $ip2id;
echo ".";
echo $ip3id;
echo ".";
echo $ip4id;
?>
例輸出結果為 218.28.131.182
這個程序的特點是,生成的ip第一個字段時在指定范圍內的,設定的幾個是國內常見號段,也就是說生成的ip地址大部分是國內的
核心代碼:
復制代碼 代碼如下:
<?php
$arr_1 = array("http://66.249.89.99","http://66.249.89.104","http://74.125.71.105");
$randarr= mt_rand(0,count($arr_1)-1);
$gip= $arr_1[$randarr];
echo $gip."$randarr";
?>