日期:2014-05-17 浏览次数:20621 次
function sina($ip)
{
$php_runtime = microtime(TRUE);
$str = file_get_contents("http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=".$ip);
$tmp = explode(" ",$str);
(isset($tmp[4]) && !empty($tmp[4])) ? $location['country'] = $tmp[4] : $location['country'] = null;
(isset($tmp[5]) && !empty($tmp[5])) ? $location['city'] = $tmp[5] : $location['city'] = null;
(empty($tmp[6]) || !preg_match("/电/",$str) || !preg_match("/通/",$str)) ? $location['sp'] = $tmp[7] : $location['sp'] = $tmp[6];
$location['time'] = microtime(TRUE) - $php_runtime;
if(!empty($location))
return $location;
else
return false;
}
------解决方案--------------------
通过用户来访的IP地址可以算出该IP属于哪个子网,如110.80.0.0/13
将全中国可划分的子网存在一个数组中,判断是否在这个数组中就行了。
不需要再去其他接口查询地址,然后根据地址或运营商的名字来判断,反而麻烦。
PS:这个数组不大,不到800条。
换算的方法请看此页面:http://url.cn/0TCFrY 内附全中国可划分子网的excel下载
------解决方案--------------------
ftp://ftp.apnic.net/public/apnic/stats/apnic/delegated-apnic-latest
apnic|CN|ipv4|180.212.0.0|131072|20091001|allocated
这就是国内的. 分析提取. 然后过滤IP就可以了