怎么通过ip获取域名?

WBOY
Release: 2016-06-13 13:17:13
Original
1137 people have browsed it

如何通过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\.]*)(?:\/.*)?/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 class="brush:php;toolbar:false">";
print_r($result); <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!