首頁 > 後端開發 > php教程 > 怎么通过ip获取域名?

怎么通过ip获取域名?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-06-13 10:44:32
原創
1432 人瀏覽過

如何通过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");//csdnecho "<pre class="brush:php;toolbar:false">";print_r($result);<div class="clear">
                 
              
              
        
            </div>
登入後複製
相關標籤:
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板