当前位置: 首页 > 百度/baidu, 网络资源 > 正文

教你识别真假蜘蛛(baidu,google,Msn,sogou,soso等)的方法

搜索引擎基本上由最先google,和国内的baidu统一了。刚开始比较混乱,后期有很多规则协议,可以遵循。基本上一些新兴的搜索引擎在访问站点时候,都会延用google制定的一些规则。它们一般都会有特定的user-agent,但是,如果我们只通过user-agent去识别搜索蜘蛛的话,那样第三方抓取程序,都会去伪造个user-agent。变成搜索蜘蛛的,如:Googlebot/2.1 (+http://www.googlebot.com/bot.html) 是,google蜘蛛的值。

现在一般搜索引擎都提供一个DNS 反向IP查询功能,只需要把访问来的IP 通过反向查询域名,看是不是搜索引擎域名。这样伪造的爬虫工具,就会被很容易识别了。

具体识别真假蜘蛛只需要:

1,判断user-agent是否满足蜘蛛格式

2,然后进一步确定IP 反解析域名是否属于该搜索引擎域名.

 

搜索引擎 user-agent(包含) 是否PTR 备注
google Googlebot host ip  得到域名:googlebot.com主域名
baidu Baiduspider host ip  得到域名:*.baidu.com 或 *.baidu.jp
yahoo Yahoo! host ip  得到域名:inktomisearch.com主域名
Sogou Sogou × *Sogou web spider/3.0(+http://www.sogou.com/docs/help/webmasters.htm#07″)
*Sogou Push Spider/3.0(+http://www.sogou.com/docs/help/webmasters.htm#07″)
网易 YodaoBot × *Mozilla/5.0 (compatible; YodaoBot/1.0;http://www.yodao.com/help/webmaster/spider/”; )
MSN MSNBot host ip  得到域名:live.com主域名
360 360Spider × Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.8.0.11)  Firefox/1.5.0.11; 360Spider
soso Sosospider × Sosospider+(+http://help.soso.com/webspider.htm)
bing bingbot host ip  得到域名:msn.com主域名

 

以上是我整理一些常用搜索引擎的user-agent特征码,以及IP反向解析情况。保证准确识别搜索引擎,我们通过IP反解析是最为准确方法。好在google,baidu,bing都有做反向解析。基本上占用了80%搜索市场了。

 

下面这个是我检测方法。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
 *检查IP及蜘蛛真实性
 * (check_spider('66.249.74.44',$_SERVER['HTTP_USER_AGENT']));
 * @copyright  http://blog.chacuo.net
 * @author 8292669
 * @param string $ip IP地址
 * @param string $ua ua地址
 * @return false|spidername  false检测失败不在指定列表中
 */
function check_spider($ip,$ua)
{
    static $spider_list=array(
    'google'=>array('Googlebot','googlebot.com'),
    'baidu'=>array('Baiduspider','.baidu.'),
    'yahoo'=>array('Yahoo!','inktomisearch.com'),
    'msn'=>array('MSNBot','live.com'),
    'bing'=>array('bingbot','msn.com')
    );
    
    if(!preg_match('/^(d{1,3}.){3}d{1,3}$/',$ip)) return false;
    if(empty($ua)) return false;
 
    foreach ($spider_list as $k=>$v)
    {
        ///如果找到了
        if(stripos($ua,$v[0])!==false)
        {
            $domain gethostbyaddr($ip);
            if($domain && stripos($domain,$v[1])!==false)
            {
                return $k;
            }
        }
    }
    return false;
}

本文固定链接: https://www.zhzx.info/archives/528 | 赵泽鑫'S Blog

该日志由 zhzx3638 于2016年04月27日发表在 百度/baidu, 网络资源 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: 教你识别真假蜘蛛(baidu,google,Msn,sogou,soso等)的方法 | 赵泽鑫'S Blog

教你识别真假蜘蛛(baidu,google,Msn,sogou,soso等)的方法:等您坐沙发呢!

发表评论

您必须 [ 登录 ] 才能发表留言!