Forum Moderators: open
THis will only help on sites that only use ASP.NET
I hope this helps someone. I launched it so far and it works well. I have an email function that also gets called when a bad bot goes to our site, so I know that they tried to visit. I actively track all visits on the site, so I can then see if they found a way in (usually not). So this is pretty successful. My next project is to make this add the bad bots dynamically... probably into a textfile using a badBot trap. We'll see :)
Scott
== START page blacklist.ascx... ==
<script language="VB" runat="server">
public badBots as string = "Mozilla/3.0 (compatible; Indy Library),CBrowse,DBrowse,DDemo,Demo Bot,DSurf15a,EBrowse,Educate Search,Franklin Locator,FSurf15a,Full Web Bot,Industry Program,Mac Finder,Missauga Locate,Missigua Locator,PBrowse,PEval,Production Bot,PSurf15a,RBrowse,RSurf15a,SSurf15a"
private function get_ua_status()
dim status as boolean = false
dim ua as string = Request.UserAgent
dim badBotsArray as array = badBots.split(",")
dim badBotsSize as integer = uBound(badBotsArray)
dim i as integer = 0
do while (i <= badBotsSize)
if (left(ua, len(badBotsArray(i))) = badBotsArray(i)) then
status = true
exit do
end if
i = i + 1
loop
return status
end function
</script>
== end blacklist.ascx ==
== start global.asax ==
<!--#include file="blacklist.ascx"-->
<script language="VB" runat="server">
Sub Session_start(sender as object, e as eventargs)
dim status as boolean = get_ua_status()
if (status = true) then
response.redirect([Blacklist Page URL goes here])
end if
End Sub
</script>
== end global.asax ==
Just a thought from someone who's built something similar in classic ASP
- Tony
Sorry, I do not know ASP, but I use Red Expressions in my apache, and have found great flexibility doing so!
dave
It simply grabs the current user-agent and runs it against the regular expression I've put into the constant, and if you happen to be using either Opera, Lynx or the Google proxy (or know how to fake it) then it prints some additional text.
I picked these three because they happened to cover both full patterns+wildcards as well as partial suffix and prefix patterns.
Another plus is that the basic content of all regular expressions are inter-operable rather than the MS version being incompatible with everything else.
Function TestRegExp( ByVal sInput, ByVal sRegExp )
'Code to evaluate a regular expression using the regexp object
Dim objRegularTestRegExp = False
Set objRegular = New RegExp
objRegular.IgnoreCase = True
On Error Resume Next
objRegular.Pattern = sRegExp
TestRegExp = objRegular.Test( sInput )If Err.Number <> 0 Then
Response.Write "REGEXP ::" & sRegExp
Response.Write "INPUT ::" & sInput
End IfOn Error Goto 0
Set objRegular = Nothing
End Function
Const csSECrawlers = "^Opera/\d\.\d*\s\(.+;.*\)\s*.*$¦^Lynx/\d\.\d+¦\s\(Google\s(WAP¦CHTML)\sProxy/\d\.\d\)$"
Response.Write "<p>***START***</p>"
If TestRegExp( Request.ServerVariables("HTTP_USER_AGENT"), csSECrawlers ) Then
Response.Write "you're either on opera, lynx or using the google mobile proxy!"
End If
Response.Write "<p>***END***</p>"