相比用一些地址字典好很多,毕竟自己的字典不可能经常更新
通过ip138获取ip真实地址/* <br>
$pro 使用(sina,ip138)可选 <br>
*/ <br>
public function get_ip_address($ip,$pro='ip138') <br>
{ <br>
$ip_address = ''; <br>
if($ip == '127.0.0.1') <br>
{ <br>
$ip_address = '本机 127.0.0.1'; <br>
}else if($pro=='ip138') <br>
{ <br>
<br>
$url = 'http://www.ip138.com/ips138.asp?ip='.$ip; <br>
$content = file_get_contents($url ); <br>
preg_match("/<ul><li>[\s|\S]*?/",$content,$matches); <br>
$ip_address = iconv('gbk','utf-8',$matches[0]); <br>
<br>
}else <br>
{ <br>
$url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip='.$ip; <br>
$content = file_get_contents($url ); <br>
$content = str_replace('var remote_ip_info =', '', $content); <br>
$content = rtrim($content,';'); <br>
$content = trim($content); <br>
$content = json_decode($content,true); <br>
if($content) <br>
{ <br>
$ip_address = $content['country'].' '.$content['province'].' '.$content['city'].' '.$content['district'].' '.$content['isp'].' '.$content['type'].' '.$content['desc']; <br>
} <br>
<br>
} <br>
return $ip_address; <br>
} </li></ul>
转载注明:雷劈网
AD:真正免费,域名+虚机+企业邮箱=0元