Forum Moderators: open
For the past several days, a bot has been really annoying the crap out of me. I mean "REALLY" getting me PO'd.
So, I created a couple lines of code. It reads the first 20 characters of the user agent and if it's the one I've determined I don't want looking at my page, I send it packing before the page even has time to be completely fetched. (And in this example, it also plays a little bit of a rude trick on the fellow in question).
Obviously, you can add more "IF" statements which will turn the variable "BAD" to "Yes".
Just copy and paste the code below to the <head> of your asp page. (Not sure if it works in ".NET" or not, though - probably needs a mod).
Change the "Mozilla/3.01_(compat" in the following line:
mid(Agent,1,20) = "Mozilla/3.01_(compat"
to the first 20 characters of the agent you want to ban.
<% Agent = request.servervariables("HTTP_User_Agent")%> <% If mid(Agent,1,20) = "Mozilla/3.01_(compat" then bad = "Yes"%>
<% if Bad = "Yes" then %>
<meta http-equiv=Refresh content="0; URL=http://www.fbi.gov/">
<% end if %>
Enjoy and I hope someone finds this useful!
G.
I would also use a Response.Redirect instead of
<meta http-equiv=Refresh content="0; URL=http://www.fbi.gov/">
That way you just throw them away without serving them anything.
[edited by: korkus2000 at 2:25 pm (utc) on June 25, 2002]
Wonder if I'll be getting a lot of government traffic from the FBI webmaster wondering why my site is sending them so many referrals. ;)
G.