Block IP Address

Do you like this ASP code snippet? Tweet it, share it on Facebook or download the snippet.

The code snippet below will detect the visitor’s IP address and check against the IP address you don’t want accessing your website; if the addresses match, then our visitor will be redirected to the page “no_access.asp”.

<%
Dim sBlockedIP
sBlockedIP = Request.ServerVariables("REMOTE_ADDR")
'check if the IP is the one that is blocked
If sBlockedIP = "127.0.0.1" Then
'if IP address is banned then redirect to no_access.asp
Response.Redirect "no_access.asp"
End If
%>