<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>程默的博客 &#187; 搜索引擎</title>
	<atom:link href="http://blog.chacuo.net/tag/%e6%90%9c%e7%b4%a2%e5%bc%95%e6%93%8e/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.chacuo.net</link>
	<description>web原理、web架构、web安全、web性能、服务器性能、服务器架构、服务器安全;你不能预知明天，但你可以利用今天。你不能样样顺利，但你可以事事尽力!</description>
	<lastBuildDate>Mon, 31 Aug 2020 15:33:40 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>识别真假搜索引擎（搜索蜘蛛）方法（baidu,google,Msn,sogou,soso等)</title>
		<link>http://blog.chacuo.net/147.html</link>
		<comments>http://blog.chacuo.net/147.html#comments</comments>
		<pubDate>Tue, 04 Jun 2013 11:10:16 +0000</pubDate>
		<dc:creator>程默</dc:creator>
				<category><![CDATA[web原理]]></category>
		<category><![CDATA[学习心得]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[搜索引擎]]></category>

		<guid isPermaLink="false">http://blog.chacuo.net/?p=147</guid>
		<description><![CDATA[最近工作中遇到个问题，就是有一些资源，不希望别人很派发的抓取，这样会占用我们带宽还有资源。因此，我们对页面访问 [...]]]></description>
				<content:encoded><![CDATA[<p>最近工作中遇到个问题，就是有一些资源，不希望别人很派发的抓取，这样会占用我们带宽还有资源。因此，我们对页面访问做了频率限制。这样一来，又怕搜索蜘蛛给限制了。 因此，我们有个需求，就是除了常见搜索蜘蛛，其它都要做频率限制。 工作就变成了，首先我们怎么样正确表示搜索蜘蛛。</p>
<ul>
<li>
<h3><strong>怎么样识别搜索蜘蛛</strong></h3>
</li>
</ul>
<h3><strong></strong></h3>
<p>搜索引擎基本上由最先google,和国内的baidu统一了。刚开始比较混乱，后期有很多规则协议，可以遵循。基本上一些新兴的搜索引擎在访问站点时候，都会延用google制定的一些规则。它们一般都会有特定的user-agent，但是，如果我们只通过user-agent去识别搜索蜘蛛的话，那样第三方抓取程序，都会去伪造个user-agent。变成搜索蜘蛛的，如：Googlebot/2.1 (+<a href="http://www.googlebot.com/bot.html)%C2%A0">http://www.googlebot.com/bot.html) </a>是，google蜘蛛的值。</p>
<p>现在一般搜索引擎都提供一个DNS 反向IP查询功能，只需要把访问来的IP 通过反向查询域名，看是不是搜索引擎域名。这样伪造的爬虫工具，就会被很容易识别了。 具体识别真假蜘蛛只需要：<u><font color="#0000ff">1，判断user-agent是否满足蜘蛛格式 2，然后进一步确定IP 反解析域名是否属于该搜索引擎域名.</font></u></p>
<table class="table" border="0" cellspacing="1" cellpadding="4" width="732" align="center">
<tbody></tbody>
<thead>
<tr>
<td width="102"><strong>搜索引擎</strong></td>
<td width="104"><strong>user-agent(包含)</strong></td>
<td width="77"><strong>是否PTR</strong></td>
<td width="442"><strong>备注</strong></td>
</tr>
</thead>
<tbody>
<tr>
<td width="102">google</td>
<td width="104">Googlebot</td>
<td width="77">√</td>
<td width="442">host ip&#160; 得到域名：googlebot.com主域名</td>
</tr>
<tr>
<td width="102">baidu</td>
<td width="104">Baiduspider</td>
<td width="77">√</td>
<td width="442">host ip&#160; 得到域名：*.baidu.com 或 *.baidu.jp</td>
</tr>
<tr>
<td width="102">yahoo</td>
<td width="104">Yahoo!</td>
<td width="77">√</td>
<td width="442">host ip&#160; 得到域名：inktomisearch.com主域名 </td>
</tr>
<tr>
<td width="102">Sogou</td>
<td width="104">Sogou</td>
<td width="77">×</td>
<td width="442">
<p>*Sogou web spider/3.0(+<a href="http://www.sogou.com/docs/help/webmasters.htm#07&Prime;)&nbsp;">http://www.sogou.com/docs/help/webmasters.htm#07″) </a>            <br />*Sogou Push Spider/3.0(+<a href="http://www.sogou.com/docs/help/webmasters.htm#07&Prime;)&nbsp;">http://www.sogou.com/docs/help/webmasters.htm#07″) </a></p>
</td>
</tr>
<tr>
<td width="102">网易</td>
<td width="104">YodaoBot</td>
<td width="77">×</td>
<td width="442">*Mozilla/5.0 (compatible; YodaoBot/1.0; <a href="http://www.yodao.com/help/webmaster/spider/%E2%80%9D;">http://www.yodao.com/help/webmaster/spider/”;</a> ) </td>
</tr>
<tr>
<td width="102">MSN</td>
<td width="104">MSNBot</td>
<td width="77">√</td>
<td width="442">host ip&#160; 得到域名：live.com主域名</td>
</tr>
<tr>
<td width="102">360</td>
<td width="104">360Spider</td>
<td width="77">×</td>
<td width="442">Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.8.0.11)&#160; Firefox/1.5.0.11; 360Spider</td>
</tr>
<tr>
<td width="102">soso</td>
<td width="104">Sosospider</td>
<td width="77">×</td>
<td width="442">Sosospider+(+http://help.soso.com/webspider.htm)</td>
</tr>
<tr>
<td width="102">bing</td>
<td width="104">bingbot</td>
<td width="77">√</td>
<td width="442">host ip&#160; 得到域名：msn.com主域名</td>
</tr>
</tbody>
</tbody>
</table>
<p>以上是我整理一些常用搜索引擎的user-agent特征码，以及IP反向解析情况。保证准确识别搜索引擎，我们通过IP反解析是最为准确方法。好在google,baidu,bing都有做反向解析。基本上占用了80%搜索市场了。下面，我是我检测方法。</p>
<ul>
<li>
<h3><strong>PHP反解析IP方法</strong></h3>
</li>
</ul>
<blockquote><pre style="text-indent: 0px" lang="php">&lt;?php
/**
 *检查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'=&gt;array('Googlebot','googlebot.com'),
	'baidu'=&gt;array('Baiduspider','.baidu.'),
	'yahoo'=&gt;array('Yahoo!','inktomisearch.com'),
	'msn'=&gt;array('MSNBot','live.com'),
	'bing'=&gt;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=&gt;$v)
	{
		///如果找到了
		if(stripos($ua,$v[0])!==false)
		{
			$domain = gethostbyaddr($ip);

			if($domain &amp;&amp; stripos($domain,$v[1])!==false)
			{
				return $k;
			}
		}
	}
	return false;
}</pre>
</blockquote>
<p>&#160;</p>
<p>目前只加入几个搜索引擎检测，这些是可以做反解析查询的。不能做反解析查询的，最好做速度限制，用户会使用它们来伪造搜索引擎来抓取你的资源。欢迎大家交流，先写到这里了。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.chacuo.net/147.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
