Hey--I was hoping someone could post some code or a link to a script that can redirect users based on their IP address using ASP. I need to be able to redirect entire IP ranges, e.g. 32.258.24.* would go to a certain address. Thanks for any help!
Splitting the visitors IP and blocked IP with "." and comparising the parts may work. <% strVisitorIP = Request.ServerVariables("REMOTE_ADDR") 'e.g. strVisitorIP = 32.258.24.36 strBlockedIP = "32.258.24.*" arrVisIPParts = Split(strVisitorIP, ".") ' arrVisIPParts(0) = 32 ' arrVisIPParts(1) = 258 ' arrVisIPParts(2) = 24 ' arrVisIPParts(3) = 36 arrBlockedIPParts = Split(strBlockedIP, ".") ' arrBlockedIPParts(0) = 32 ' arrBlockedIPParts(1) = 258 ' arrBlockedIPParts(2) = 24 ' arrBlockedIPParts(3) = 36 ' Now check if the first 3 parts are same If (arrVisIPParts(0) = arrBlockedIPParts(0)) AND (arrVisIPParts(1) = arrBlockedIPParts(1)) AND (arrVisIPParts(2) = arrBlockedIPParts(2)) Then Response.Write "Your IP is blocked" Response.End End If %> This is a method but I think coding this with regular expression is easier..
Easier to find the last full stop/ period and cut off it and beyond of both the visitors IP and your blocked IP in the cases of something like 32.258.24.* and then do a single If equals statement.