April 22, 2008

Write ASP and need a way to block IP’s from your site?

This demonstrates how to ban a single IP address, later, I’ll show how to ban whole networks but chances are you will be able to work that out for yourself anyway after reading this anyway.

If global.asa does not exist then create it and add the following:

sub session_onstart
 
  ip = request.servervariables("Remote_Addr")
 
  select case ip
    case "111.111.111.111", "111.111.111.112", "111.111.111.123"
      response.redirect "http://www.example.com"
  end select
 
end sub

Replace 111.111.111.11x with the IP addresses you wish to ban, note they are comma separated and the last one is not followed with a comma.

You can change the redirection to a page on your site that informs them they are no longer allowed (a bit vindictive), to a blank page is probably best or you could even forward them on to a competitor :D

Post a Comment