神马搜索来源记录以及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代码


<span class="prism-token prism-php"><span class="prism-token prism-delimiter">&lt;?php</span>
<span class="prism-token prism-comment" spellcheck="true">//飞鸟慕鱼博客</span>
<span class="prism-token prism-keyword">function</span> <span class="prism-token prism-function">is_yisouspider</span><span class="prism-token prism-punctuation">(</span><span class="prism-token prism-punctuation">)</span><span class="prism-token prism-punctuation">{</span>
    <span class="prism-token prism-variable">$ua</span><span class="prism-token prism-operator">=</span> <span class="prism-token prism-function">addslashes</span><span class="prism-token prism-punctuation">(</span><span class="prism-token prism-function">strtolower</span><span class="prism-token prism-punctuation">(</span><span class="prism-token prism-global">$_SERVER</span><span class="prism-token prism-punctuation">[</span><span class="prism-token prism-string">'HTTP_USER_AGENT'</span><span class="prism-token prism-punctuation">]</span><span class="prism-token prism-punctuation">)</span><span class="prism-token prism-punctuation">)</span><span class="prism-token prism-punctuation">;</span>
    <span class="prism-token prism-keyword">if</span> <span class="prism-token prism-punctuation">(</span><span class="prism-token prism-function">strpos</span><span class="prism-token prism-punctuation">(</span><span class="prism-token prism-variable">$ua</span><span class="prism-token prism-punctuation">,</span> <span class="prism-token prism-string">'yisouspider'</span><span class="prism-token prism-punctuation">)</span> <span class="prism-token prism-operator">!==</span> <span class="prism-token prism-boolean">false</span><span class="prism-token prism-punctuation">)</span> <span class="prism-token prism-punctuation">{</span>
        <span class="prism-token prism-keyword">return</span> <span class="prism-token prism-boolean">true</span><span class="prism-token prism-punctuation">;</span>
    <span class="prism-token prism-punctuation">}</span>
    <span class="prism-token prism-keyword">return</span> <span class="prism-token prism-boolean">false</span><span class="prism-token prism-punctuation">;</span>
<span class="prism-token prism-punctuation">}</span>
<span class="prism-token prism-delimiter">?&gt;</span></span>

复制

函数调用:


<span class="prism-token prism-php"><span class="prism-token prism-delimiter">&lt;?php</span>
<span class="prism-token prism-keyword">if</span><span class="prism-token prism-punctuation">(</span><span class="prism-token prism-function">is_yisouspider</span><span class="prism-token prism-punctuation">(</span><span class="prism-token prism-punctuation">)</span><span class="prism-token prism-punctuation">)</span><span class="prism-token prism-punctuation">{</span>
    <span class="prism-token prism-keyword">echo</span> <span class="prism-token prism-string">'yes'</span><span class="prism-token prism-punctuation">;</span>
<span class="prism-token prism-punctuation">}</span><span class="prism-token prism-keyword">else</span><span class="prism-token prism-punctuation">{</span>
    <span class="prism-token prism-keyword">echo</span> <span class="prism-token prism-string">'no'</span><span class="prism-token prism-punctuation">;</span>
<span class="prism-token prism-punctuation">}</span>
<span class="prism-token prism-delimiter">?&gt;</span></span>

复制

神马搜索引擎蜘蛛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

发表评论

邮箱地址不会被公开。 必填项已用*标注