欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

怎么通过ip获取域名?

程序员文章站 2024-01-28 19:38:22
...
如何通过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="/([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 "
";print_r($result);
怎么通过ip获取域名?

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频