通过ip138获取ip真实地址

浏览:8621 发布日期:2014/10/20 分类:功能实现 关键字: 获取ip真实地址 ip138 新浪ip
相比用一些地址字典好很多,毕竟自己的字典不可能经常更新
通过ip138获取ip真实地址/* 
    $pro 使用(sina,ip138)可选 
*/  
public function get_ip_address($ip,$pro='ip138')  
{  
    $ip_address  = '';  
    if($ip == '127.0.0.1')  
    {  
        $ip_address = '本机 127.0.0.1';  
    }else if($pro=='ip138')  
    {  
  
        $url = 'http://www.ip138.com/ips138.asp?ip='.$ip;  
        $content = file_get_contents($url );  
        preg_match("/<ul class=\"ul1\"><li>[\s|\S]*?<\/li><\/ul>/",$content,$matches);   
        $ip_address = iconv('gbk','utf-8',$matches[0]);  
  
    }else  
    {  
        $url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip='.$ip;  
        $content = file_get_contents($url );  
        $content = str_replace('var remote_ip_info =', '', $content);  
        $content = rtrim($content,';');  
        $content = trim($content);  
        $content = json_decode($content,true);  
        if($content)  
        {  
            $ip_address = $content['country'].' '.$content['province'].' '.$content['city'].' '.$content['district'].' '.$content['isp'].' '.$content['type'].' '.$content['desc'];  
        }  
          
    }  
    return $ip_address;  
}  
转载注明:雷劈网
评论( 相关
后面还有条评论,点击查看>>