Last active
September 8, 2015 07:35
-
-
Save MJomaa/9a3b9f5f66b5acf7db15 to your computer and use it in GitHub Desktop.
Middleware to block bad bots in ASP.NET 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BadBotMiddleWare | |
{ | |
private readonly RequestDelegate _next; | |
public ImmutableHashSet<string> List { get; set; } | |
public BadBotMiddleWare(RequestDelegate next) | |
{ | |
_next = next; | |
List = new[] | |
{ | |
"Aboundex", | |
"80legs", | |
"360Spider", | |
"Java", | |
"Cogentbot", | |
"Alexibot", | |
"asterias", | |
"attach", | |
"BackDoorBot", | |
"BackWeb", | |
"Bandit", | |
"BatchFTP", | |
"Bigfoot", | |
"Black.Hole", | |
"BlackWidow", | |
"BlowFish", | |
"BotALot", | |
"Buddy", | |
"BuiltBotTough", | |
"Bullseye", | |
"BunnySlippers", | |
"Cegbfeieh", | |
"CheeseBot", | |
"CherryPicker", | |
"ChinaClaw", | |
"Collector", | |
"Copier", | |
"CopyRightCheck", | |
"cosmos", | |
"Crescent", | |
"Custo", | |
"AIBOT", | |
"DISCo", | |
"DIIbot", | |
"DittoSpyder", | |
"Download\\ Demon", | |
"Download\\ Devil", | |
"Download\\ Wonder", | |
"dragonfly", | |
"Drip", | |
"eCatch", | |
"EasyDL", | |
"ebingbong", | |
"EirGrabber", | |
"EmailCollector", | |
"EmailSiphon", | |
"EmailWolf", | |
"EroCrawler", | |
"Exabot", | |
"Express\\ WebPictures", | |
"Extractor", | |
"EyeNetIE", | |
"Foobot", | |
"flunky", | |
"FrontPage", | |
"Go-Ahead-Got-It", | |
"gotit", | |
"GrabNet", | |
"Grafula", | |
"Harvest", | |
"hloader", | |
"HMView", | |
"HTTrack", | |
"humanlinks", | |
"IlseBot", | |
"Image\\ Stripper", | |
"Image\\ Sucker", | |
"Indy\\ Library", | |
"InfoNaviRobot", | |
"InfoTekies", | |
"Intelliseek", | |
"InterGET", | |
"Internet\\ Ninja", | |
"Iria", | |
"Jakarta", | |
"JennyBot", | |
"JetCar", | |
"JOC", | |
"JustView", | |
"Jyxobot", | |
"Kenjin.Spider", | |
"Keyword.Density", | |
"larbin", | |
"LexiBot", | |
"lftp", | |
"libWeb/clsHTTP", | |
"libwhisker", | |
"libwww-perl", | |
"likse", | |
"LinkextractorPro", | |
"LinkScan/8.1a.Unix", | |
"LNSpiderguy", | |
"LinkWalker", | |
"lwp-trivial", | |
"LWP::Simple", | |
"Magnet", | |
"Mag-Net", | |
"MarkWatch", | |
"Mass\\ Downloader", | |
"Mata.Hari", | |
"Memo", | |
"Microsoft.URL", | |
"Microsoft\\ URL\\ Control", | |
"MIDown\\ tool", | |
"MIIxpc", | |
"Mirror", | |
"Missigua\\ Locator", | |
"Mister\\ PiX", | |
"moget", | |
"Mozilla/3.Mozilla/2.01", | |
"Mozilla.*NEWT", | |
"NAMEPROTECT", | |
"Navroad", | |
"NearSite", | |
"NetAnts", | |
"Netcraft", | |
"NetMechanic", | |
"NetSpider", | |
"Net\\ Vampire", | |
"NetZIP", | |
"NextGenSearchBot", | |
"NG", | |
"NICErsPRO", | |
"niki-bot", | |
"NimbleCrawler", | |
"Ninja", | |
"NPbot", | |
"Octopus", | |
"Offline\\ Explorer", | |
"Offline\\ Navigator", | |
"Openfind", | |
"OutfoxBot", | |
"PageGrabber", | |
"Papa\\ Foto", | |
"pavuk", | |
"pcBrowser", | |
"PHP\\ version\\ tracker", | |
"Pockey", | |
"ProPowerBot/2.14", | |
"ProWebWalker", | |
"psbot", | |
"Pump", | |
"QueryN.Metasearch", | |
"RealDownload", | |
"Reaper", | |
"Recorder", | |
"ReGet", | |
"RepoMonkey", | |
"RMA", | |
"Siphon", | |
"SiteSnagger", | |
"SlySearch", | |
"SmartDownload", | |
"Snake", | |
"Snapbot", | |
"Snoopy", | |
"sogou", | |
"SpaceBison", | |
"SpankBot", | |
"spanner", | |
"Sqworm", | |
"Stripper", | |
"Sucker", | |
"SuperBot", | |
"SuperHTTP", | |
"Surfbot", | |
"suzuran", | |
"Szukacz/1.4", | |
"tAkeOut", | |
"Teleport", | |
"Telesoft", | |
"TurnitinBot/1.5", | |
"The.Intraformant", | |
"TheNomad", | |
"TightTwatBot", | |
"Titan", | |
"True_Robot", | |
"turingos", | |
"TurnitinBot", | |
"URLy.Warning", | |
"Vacuum", | |
"VCI", | |
"VoidEYE", | |
"Web\\ Image\\ Collector", | |
"Web\\ Sucker", | |
"WebAuto", | |
"WebBandit", | |
"Webclipping.com", | |
"WebCopier", | |
"WebEMailExtrac.*", | |
"WebEnhancer", | |
"WebFetch", | |
"WebGo\\ IS", | |
"Web.Image.Collector", | |
"WebLeacher", | |
"WebmasterWorldForumBot", | |
"WebReaper", | |
"WebSauger", | |
"Website\\ eXtractor", | |
"Website\\ Quester", | |
"Webster", | |
"WebStripper", | |
"WebWhacker", | |
"WebZIP", | |
"Whacker", | |
"Widow", | |
"WISENutbot", | |
"WWWOFFLE", | |
"WWW-Collector-E", | |
"Xaldon", | |
"Xenu", | |
"Zeus", | |
"ZmEu", | |
"Zyborg", | |
"Acunetix", | |
"FHscan", | |
"Baiduspider", | |
"Yandex" | |
}.ToImmutableHashSet(); | |
} | |
public async Task Invoke(HttpContext context) | |
{ | |
if (List.Any(s => context?.Request?.Headers["User-Agent"].ToString().IndexOf(s, StringComparison.OrdinalIgnoreCase) >=0)) | |
{ | |
return; | |
} | |
await _next(context); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment