Forum Moderators: open

Message Too Old, No Replies

Ban Those Bad Bots

ASP, NT Server, No .htaccess - What's a Dude to Do? Here's What...

         

Grumpus

2:20 pm on Jun 25, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On a windows NT server, we don't have have an .htaccess file. Those hackers ignore the robots.txt. It's a pain in the buttox to contact the host every time you've got a new bot to ban. (And, maybe it's just your preference, and if you're on a shared server, you don't want everyone on the server to have the bot banned - some folks might like it).

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.

korkus2000

2:24 pm on Jun 25, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



An easier way to do that is to use your global.asa. Place the code in the OnSessionStart event handler. That way you won't have to put it on every asp page.

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]

Grumpus

2:25 pm on Jun 25, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ahhh, good point! Thanks!

G.

korkus2000

2:30 pm on Jun 25, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am using a global.asa that is pulling both ip and user agent from a database. If I get both ip and user agent matches then I toss them. I do like throwing them to the FBI :)

Grumpus

2:34 pm on Jun 25, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah. That's my favorite part, too. I'm trying to figure out a way to toss them through my global.asa and it's not coming to me very quickly. Oh well. I've already got it set up on my site, so I'll leave it like it is.

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.