日期:2014-05-17  浏览次数:20549 次

如何通过ip获取域名??
我用gethostbyaddr('里面放ip');每次只返回ip而不是返回域名,貌似只有输入127.0.0.1才能返回域名,百度,和谷歌都不行,这个函数到底咋用呢!!!!

function gethost ($ip)
{
  return ( preg_match('/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.]
(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/', $ip) ) ? gethostbyaddr($ip) : false;

}

------解决方案--------------------
PHP code

function getContent($url){  
    $content=file_get_contents($url);  
    return $content;  
}  
 
function getResult($ip){  
    $pagesize=10;  
    $page=1;  
    $url="http://cn.bing.com/search?q=ip%3A$ip&first=$page";  
    $result=array();  
    do 
    {  
        $url="http://cn.bing.com/search?q=ip%3A$ip&first=$page";  
        $content=getContent($url);  
        $pattern="/<cite>([a-zA-Z0-9\.]*)(?:\/.*)?<\/cite>/isU";  
        preg_match_all($pattern, $content, $matches);  
        $result=array_merge($result,$matches[1]);  
        $nextpage=strpos($content, "下一页");  
        $page=$page+$pagesize;  
    }while($nextpage);  
      
    $result=array_values(array_unique($result));  
      
    return $result;  
}  
 
// 调用方法
$result=getResult("220.181.111.85");
//$result=getResult("117.79.93.222");//csdn
echo "<pre>";
print_r($result);