如何阻止糟糕的不明机器人爬我的网站



我该如何抵御恶意的不明机器人对我的网站进行爬网?一些名字不在Apache的cPanel中的坏机器人正在糟糕地访问我的网站带宽。

我曾在batgap.com-robots.txt上尝试过robots.txt,也被.htaccess屏蔽,但带宽使用率没有提高。我不知道这些机器人的IP,所以无法通过IP地址阻止它们。这些机器人消耗了太多的网站带宽,因此我需要从服务器增加带宽。

我来自Incapsula,我们经常处理坏机器人。

我们最近发布了一项与机器人相关的研究,该研究提供了对问题范围的见解(http://www.incapsula.com/the-incapsula-blog/item/225-what-google-doesnt-show-you-31-of-website-traffic-can-harm-your-business),鉴于这些数据,我不得不同意@LeonardChallis的观点——你根本无法手动处理机器人保护。

话虽如此,还是有机器人保护解决方案,甚至是免费的(包括我们在内),可以帮助您处理糟糕的机器人。

BTW-就像你提到的,糟糕的机器人访问的一个副产品是带宽损失。我们最近意识到,与机器人相关的带宽使用量是多么惊人。这本身就是一个有趣的话题。我们相信,通过避免糟糕的机器人流量,托管提供商实际上可以大大提高他们的效率(希望利用这一点来降低成本或改善服务)。一旦你想象了这对社会和商业的影响,你就可以理解这个糟糕的机器人问题的真正范围,它远远超出了所造成的直接损害。

我使用PHP阻止"坏机器人"。我主要在IP地址中进行过滤,然后由用户代理进行过滤。我让"坏机器人"等待长达999秒,然后返回一个非常小的网页。通常(总是)互联网连接超时并且返回零(0)个字节。最棒的是,在找到下一个受害者之前,我已经把他们推迟了几分钟。http://gelm.net/How-to-block-Baidu-with-PHP.htm

不幸的是,robots.txt有时会被这些"坏机器人"忽略,尽管如果问题更多的是你不想看到的真正的搜索引擎蜘蛛,他们应该考虑到这一点。我想有了CPanel,你可以进入网络服务器(apache)日志吗?在那里你可以找到两个东西:IP和用户代理。你可以在那里找到罪魁祸首,并将其添加到你的robots.txt和.htaccess中。请注意,.htacccess拒绝IP地址的规则比仅仅依赖robots.txt要好得多,因为你从机器人创建者手中夺走了选择权。

如果你知道特定的机器人在做这件事,你应该能够从论坛上获得IP地址和用户代理,但如果这是一件更普遍的事情,那么我真的担心这更像是一项手动工作。

还有其他方法可以使用,效果各不相同,例如mod_security(http://www.askapache.com/htaccess/modsecurity-htaccess-tricks.html)但这意味着您必须访问您的web服务器配置。

最后,你可以检查指向你网站的链接(使用谷歌上的链接:选项)。有时,如果你在垃圾邮件论坛上有链接,这会增加机器人来找你的机会。也许你可以在apache日志中查看referer URL,但这一切都是基于很多假设,如果它有很大的效果,你可能会很幸运。

通过PHP阻止不需要的机器人/蜘蛛访客

说明:

将以下PHP代码放在index.PHP文件的开头。

这里的想法是将代码放在主站点的PHP主页中,这是该站点的主要入口点。

如果您有其他通过URL直接访问的PHP文件(不包括PHP包含或需要支持类型的文件),请将代码放在这些文件的开头。对于大多数PHP站点和PHP CMS站点,root的index.PHP文件是站点的主要入口点。

请记住,您的网站统计信息,即AWStats,仍将记录未知机器人(由"机器人"后面跟着空格或以下字符之一_+标识)下的点击量,但这些机器人将被阻止访问您的网站内容。

<?php
// ---------------------------------------------------------------------------------------------------------------
// Banned IP Addresses and Bots - Redirects banned visitors who make it past the .htaccess and or robots.txt files to an URL.
// The $banned_ip_addresses array can contain both full and partial IP addresses, i.e. Full = 123.456.789.101, Partial = 123.456.789. or 123.456. or 123.
// Use partial IP addresses to include all IP addresses that begin with a partial IP addresses. The partial IP addresses must end with a period.
// The $banned_bots, $banned_unknown_bots, and $good_bots arrays should contain keyword strings found within the User Agent string.
// The $banned_unknown_bots array is used to identify unknown robots (identified by 'bot' followed by a space or one of the following characters _+:,.;/-).
// The $good_bots array contains keyword strings used as exemptions when checking for $banned_unknown_bots. If you do not want to utilize the $good_bots array such as
// $good_bots = array(), then you must remove the the keywords strings 'bot.','bot/','bot-' from the $banned_unknown_bots array or else the good bots will also be banned.
   $banned_ip_addresses = array('41.','64.79.100.23','5.254.97.75','148.251.236.167','88.180.102.124','62.210.172.77','45.','195.206.253.146');
   $banned_bots = array('.ru','AhrefsBot','crawl','crawler','DotBot','linkdex','majestic','meanpath','PageAnalyzer','robot','rogerbot','semalt','SeznamBot','spider');
   $banned_unknown_bots = array('bot ','bot_','bot+','bot:','bot,','bot;','bot\','bot.','bot/','bot-');
   $good_bots = array('Google','MSN','bing','Slurp','Yahoo','DuckDuck');
   $banned_redirect_url = 'http://english-1329329990.spampoison.com';
// Visitor's IP address and Browser (User Agent)
   $ip_address = $_SERVER['REMOTE_ADDR'];
   $browser = $_SERVER['HTTP_USER_AGENT'];
// Declared Temporary Variables
   $ipfound = $piece = $botfound = $gbotfound = $ubotfound = '';
// Checks for Banned IP Addresses and Bots
   if($banned_redirect_url != ''){
     // Checks for Banned IP Address
        if(!empty($banned_ip_addresses)){
          if(in_array($ip_address, $banned_ip_addresses)){$ipfound = 'found';}
          if($ipfound != 'found'){
            $ip_pieces = explode('.', $ip_address);
            foreach ($ip_pieces as $value){
              $piece = $piece.$value.'.';
              if(in_array($piece, $banned_ip_addresses)){$ipfound = 'found'; break;}
            }
          }
          if($ipfound == 'found'){header("location: $banned_redirect_url"); exit();}
        }
     // Checks for Banned Bots
        if(!empty($banned_bots)){
          foreach ($banned_bots as $bbvalue){
            $pos1 = stripos($browser, $bbvalue);
            if($pos1 !== false){$botfound = 'found'; break;}
          }
          if($botfound == 'found'){header("location: $banned_redirect_url"); exit();}
        }
     // Checks for Banned Unknown Bots
        if(!empty($good_bots)){
          foreach ($good_bots as $gbvalue){
            $pos2 = stripos($browser, $gbvalue);
            if($pos2 !== false){$gbotfound = 'found'; break;}
          }
        }
        if($gbotfound != 'found'){
          if(!empty($banned_unknown_bots)){
            foreach ($banned_unknown_bots as $bubvalue){
              $pos3 = stripos($browser, $bubvalue);
              if($pos3 !== false){$ubotfound = 'found'; break;}
            }
            if($ubotfound == 'found'){header("location: $banned_redirect_url"); exit();}
          }
        }
   }
// ---------------------------------------------------------------------------------------------------------------
?>

最新更新