dongyi8383 2013-07-07 19:52
浏览 47
已采纳

当Web主机DNS服务器仅返回IP时,PHP通过主机验证百度搜索引擎

I've tried the following on IP addresses with user agents claiming to be the Baidu search engine. Unfortunately Just Host's DNS servers refuse to return anything but the IP address for the host.

<?php
echo 'host: '.gethostbyaddr('180.76.5.168');
echo '<br />'.shell_exec('host -W 2 180.76.5.168');
echo '<br />'.shell_exec('nslookup 180.76.5.168');
?>

Any suggestions for how to get a hold of the host name for Baidu? I've thought about trying to reference specific DNS servers if possible though I'm not sure how to do that with PHP.


Quoted output of my localhost result...

host: baiduspider-180-76-5-168.crawl.baidu.com

Server: Wireless_Broadband_Router.home Address: 192.168.1.1 Name: baiduspider-180-76-5-168.crawl.baidu.com Address: 180.76.5.168

  • 写回答

1条回答 默认 最新

  • doucitao2944 2013-07-10 05:21
    关注

    I was able to use a different DNS server via the host command via shell...

    $p = trim(trim(explode(' pointer',shell_exec('host -W 2 180.76.5.168  68.238.96.12'))[1]),'.');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?