Blocking an IP Range with ASP

Discussion in 'C#' started by kkibak, Jul 5, 2007.

  1. #1
    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!
     
    kkibak, Jul 5, 2007 IP
  2. doronty37

    doronty37 Active Member

    Messages:
    130
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #2
    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..
     
    doronty37, Jul 6, 2007 IP
  3. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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.
     
    AstarothSolutions, Jul 6, 2007 IP