<?php


printf"%u", ip2long('222.246.63.255')); //222.246.63.255    -554287105
return;

set_time_limit(2600);

require_once("../echo.php");
require_once"API/config.php");
require_once"API/databaseLite.php");
$g_config[db]['db']='ip';


/* 连接数据库 */
$DB = new databaseLite( $g_config[db]['host'], $g_config[db]['dbUser'], $g_config[db]['dbPass'],    $g_config[db]['db'],$g_config[db]['encode'] ); 


$rfile="ip.txt";
$fp = fopen($rfile,"rb");
$time1 = getmicrotime();

while (!feof($fp)) {
    
$line = fgets($fp,1024);
    
$arr = preg_split("# +#",$line);
    
//prt($arr);
$name = str_replace("\r\n","",$arr[3]);
$name = str_replace("\r","",$name);
$name = str_replace("\n","",$name);
    
$tmprow['name'= mysql_escape_string($name);
    
$tmprow['min'= sprintf"%u" , ip2long($arr[0]) );
    
$tmprow['max'= sprintf"%u" , ip2long($arr[1]) );
    
$tmprow['area'= mysql_escape_string($arr[2]);
    
$DB->insertDB( $tmprow , "ip_main" );

    
/*
    $i++;
    if ($i>100) {
        break;
    }
    
*/
}


fclose($fp);

$time1End = getmicrotime(); 
$costs = ($time1End-$time1)."\r\n";
echo $costs."<br>\n";


$fp = fopen("costs.txt","a+");
fwrite($fp,$costs);
fclose($fp);


?>

<!-- 
0.0.0.0         0.255.255.255   IANA  CZ88.NET
1.0.0.0         1.255.255.255   IANA  CZ88.NET
2.0.0.0         2.255.255.255   IANA  CZ88.NET
3.0.0.0         3.255.255.255   美国 新泽西通用电气公司
4.0.0.0         4.10.255.255    美国  CZ88.NET
4.11.0.0        4.11.255.255    美国 夏威夷
4.12.0.0        4.19.77.255     美国  CZ88.NET
4.19.78.0       4.19.78.255     美国 西南政法大学
4.19.79.0       4.19.79.63      美国 Armed Forces Radio/Television
4.19.79.64      4.21.177.111    美国  CZ88.NET
4.21.177.112    4.21.177.127    美国 Kraft Group
4.21.177.128    4.21.177.255    美国 南新汉普郡学院
4.21.178.0      4.36.124.127    美国  CZ88.NET
4.36.124.128    4.36.124.255    美国 Technical Resource Connections Inc
4.36.125.0      4.36.127.255    美国 坦帕大学
4.36.128.0      4.37.215.255    美国  CZ88.NET
4.37.216.0      4.37.219.255    美国 德克萨斯女子大学
4.37.220.0      4.41.60.255     美国  CZ88.NET
4.41.61.0       4.41.61.255     美国 EARTHLINK公司
4.41.62.0       4.43.68.255     美国  CZ88.NET
4.43.69.0       4.43.69.95      美国 罗斯门特学院
4.43.69.96      4.208.48.255    美国 Genuity用户
4.208.49.0      4.208.49.255    美国 加洲
4.208.50.0      4.237.255.255   美国 Genuity用户
-->


查询 find.php

<?php

require_once("../echo.php");
require_once"API/config.php");
require_once"API/databaseLite.php");
$g_config[db]['db']='ip';


/* 连接数据库 */
$DB = new databaseLite( $g_config[db]['host'], $g_config[db]['dbUser'], $g_config[db]['dbPass'],    $g_config[db]['db'],$g_config[db]['encode'] ); 


$time1 = getmicrotime();

$ip = $_REQUEST['q_ip']?$_REQUEST['q_ip']:$_SERVER['REMOTE_ADDR'];
$ip = trim($ip);
$ip = preg_replace("[^0-9.]","",$ip);


$findIp = sprintf("%u", ip2long($ip));

$sql="select name,area from ip_main where max>=$findIp limit 1";
$DB->setQuery($sql);
$row =$DB->loadRow(1);

prt(
$row);

$time1End = getmicrotime(); 
$costs = round($time1End-$time1,6);

?>
<form method="get" action="?">
<input type="text" name="q_ip" value="<?=$ip?>" size="40" onfocus=this.select() />
<input type="submit" value="查询" />
</form>

<?=$costs?>
<br>




CREATE TABLE `ip_main` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(100) collate gbk_bin default NULL,
  `min` int(11) unsigned NOT NULL,
  `max` int(11) unsigned NOT NULL,
  `area` varchar(100) collate gbk_bin default NULL,
  PRIMARY KEY  (`id`),
  KEY `max` (`max`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk COLLATE=gbk_bin;
Posted on 2007-01-08 20:35  古代  阅读(401)  评论(0编辑  收藏  举报