php判断神马搜索引擎蜘蛛的方法

来自:互联网
时间:2019-10-03
阅读:

今天无事查看了一下网站的访问日志,发现日志中有不少神马搜索引擎的来访记录。就写了一段php代码,用来统计一下神马搜索访问的数据,以便做出合理的优化方案。

神马搜索来源记录以及User Agent

以下为设神马搜索引擎的来访问User Agent,带用来访问的IP地址

42.156.137.14 - "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 YisouSpider/5.0 Safari/537.36"
106.11.156.57 - "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 YisouSpider/5.0 Safari/537.36"
42.156.137.33 - "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 YisouSpider/5.0 Safari/537.36"
42.156.137.44 - "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e YisouSpider/5.0 Safari/602.1"
106.11.153.124 -  "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 YisouSpider/5.0 Safari/537.36"

php判断搜索引擎是否为神马搜索

通过上面的三条 User Agent 信息,可以发现它们都有一个共同的 YisouSpider 字段,也就是说 User Agent 中含有 YisouSpider 字段的来访者即为神马搜索引擎的蜘蛛。我们可以利用php脚本,来检索 User Agent 的 YisouSpider 字段,来判断来访问者是否为神马搜索引擎的蜘蛛,并做出相应有处理

php代码

<?php
//免费资源网
function is_yisouspider(){
    $ua= addslashes(strtolower($_SERVER['HTTP_USER_AGENT']));
    if (strpos($ua, 'yisouspider') !== false) {
        return true;
    }
    return false;
}
?>

函数调用:

<?php
if(is_yisouspider()){
    echo 'yes';
}else{
    echo 'no';
}
?>

神马搜索引擎蜘蛛IP地址

以下为神马搜索引擎蜘蛛的来访IP地址,你可以通过判断IP的方式,来判断是否为神马搜索引擎。

注:个别攻击者会人伪造神马搜索引擎的 User Agent,当然IP可以被伪造

42.156.136.0/24:表示IP段,42.156.136.1 到 42.156.136.254

42.156.136.0/24

42.156.137.0/24

42.156.138.0/24

42.156.139.0/24

42.120.160.0/24

42.120.161.0/24

42.156.254.0/24

42.120.234.0/24

42.120.235.0/24

42.120.236.0/24

106.11.152.0/24

106.11.153.0/24

106.11.154.0/24

106.11.155.0/24

106.11.156.0/24

106.11.157.0/24

106.11.158.0/24

106.11.159.0/24

返回顶部
顶部