当我们向用户发送短信时,我看到来自该机器人的大量流量。我正在尝试了解有关此机器人的更多详细信息。任何描述它的作用、它的重要性以及我们是否可以阻止它的指针将不胜感激。 完整的用户代理是
Mozilla/5.0(X11;Linux x86_64)AppleWebKit/537.36(KHTML,如 Gecko)Chrome/56.0.2924.87 Safari/537.36 Google(+https://developers.google.com/+/web/snippet/)
Android 上的 Google SMS 应用程序在抓取共享 URL 以在聊天中生成预览时使用此用户代理。这通常是一件好事,因为您的客户将看到预览图像和页面标题,而不仅仅是链接。所以我不建议阻止它。
您可以在 nginx 配置上阻止 google 机器人。在 server{} 部分内添加以下内容:
if ($http_user_agent ~* "developers\.google\.com/\+/web/snippet") {
return 403;
}
这个机器人确实被一些短信 Android 应用程序用来获取我们页面的预览。
使用它的手机包括(但随着时间的推移有所变化)小米、华为、Oppo.. 对于某些网站来说,阻止它很重要。例如,我的应用程序正在发送一个确认链接,通过预览点击它会扰乱我们的统计数据和后续谁想要这个链接。
要阻止它,您可以使用以下 .htaccess 规则(如果您使用 Apache):
RewriteEngine 开启
RewriteCond %{HTTP_USER_AGENT} ^.developers.google.com/+/web/snippet。$ [NC]
重写规则“^.*$” - [F,L]
任何正在寻找
ASP.NET-MVC
解决方案的人:
创建一个帮助程序类来收集所有已知机器人的列表。对于上述情况,机器人是
Google-PageRenderer
。另一个列表是著名的机器人:
using System;
using System.Collections.Generic;
using System.Linq;
namespace MyProject.Helpers
{
public static class BotDetectionHelper
{
private static readonly HashSet<string> Bots = new HashSet<string>(StringComparer.Ordinal)
{
"Google-PageRenderer",
"Googlebot",
"Bingbot",
"Slurp",
"DuckDuckBot",
"Baiduspider",
"YandexBot",
"Sogou",
"Exabot",
"facebookexternalhit",
"LinkedInBot",
"Twitterbot",
"Pinterestbot",
"WhatsApp",
"DotBot",
"spbot/",
"James BOT",
"baidu",
"Baidu",
"/bot",
"semantic-visions.com",
"spider",
"lipperhey",
"linkdexbot/",
"MJ12bot/",
"Lipperhey-Kaus-Australis/",
"BDCbot",
"AhrefsBot",
"SemrushBot",
"Alexa",
"Uptimebot",
"Crawl",
"Spider",
"PageSpeed",
"ZoominfoBot",
"Adidxbot",
"BLEXBot",
"SEOkicks",
"BlackWidow",
"BotALot",
"Buddy",
"BuiltWith",
"Curl",
"DISCo",
"Dotbot",
"Feedfetcher-Google",
"Geekbot",
"GrapeshotCrawler",
"GT::WWW",
"HTTP::Lite",
"HubSpot",
"ia_archiver",
"Jetbot",
"JetBrains Omea Reader",
"Mechanize",
"NetcraftSurveyAgent",
"Nutch",
"Outbrain",
"Python-urllib",
"rogerbot",
"ShowyouBot",
"SiteExplorer",
"Slackbot",
"Teoma",
"Twingly Recon",
"Via",
"Wget",
"Xenu Link Sleuth",
"ZmEu"
};
public static bool IsBotAgent(string cBot) =>
Bots.Any(bot => cBot.IndexOf(bot, StringComparison.Ordinal) != -1);
}
}
然后在您的
Controller
类中创建一个方法:
private bool BotDetectionResult()
{
bool isBot = false;
string userAgent = Request.UserAgent;
try
{
if (userAgent != null)
{
isBot = BotDetectionHelper.IsBotAgent(userAgent);
}
}
catch (Exception ex)
{
//Log exception
}
return isBot;
}
用途:
bool detectBot = BotDetectionResult();
if (!detectBot)
{
//Send to database etc.
}
如果机器人列表可以更新以包含其他知名机器人,那么请随时编辑答案并添加您的条目。