i need a simple code for country ip blocking..

Discussion in 'Programming' started by greendragon, May 19, 2008.

  1. #1
    Hi,

    i want to block a country ip for my web site. i dont want this country ip's visitors to visit my web site.

    i want then to redirect to another site.

    my web site is . ASP.

    i need a simple code..please help

    Thanks
     
    greendragon, May 19, 2008 IP
  2. dylanmills

    dylanmills Peon

    Messages:
    50
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The following code should work for ASP. To get the lit of c-classes you want to block, try using the tool at www.blockacountry.com.

    Dim BlockedIPs, VisitorIP
    BlockedIPs = Array("66.128.32.","66.231.64.","157.253.0") 'List of blocked C classes
    VisitorIP = " " & Request.ServerVariables("REMOTE_ADDR") 'Visitor's IP address
    
    For Each IP in BlockedIPs 
       If (InStr(VisitorIP,IP) > 0) Then
          Response.Redirect("www.newsite.com")	
       End If		
    Next
    Code (markup):
     
    dylanmills, May 19, 2008 IP
  3. greendragon

    greendragon Well-Known Member

    Messages:
    497
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    103
    #3
    i couldnt add this code at my ASP site

    can you please write the exact code. it gives error.
     
    greendragon, May 19, 2008 IP
  4. dylanmills

    dylanmills Peon

    Messages:
    50
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Make sure you are wrapping the code in <% and %> and put the script at the top of the page. If that still doesn't work, please let me know what the error is.
     
    dylanmills, May 19, 2008 IP
  5. greendragon

    greendragon Well-Known Member

    Messages:
    497
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    103
    #5
    i sent you PM

    thank you
     
    greendragon, May 19, 2008 IP
  6. livingearth

    livingearth Well-Known Member

    Messages:
    1,469
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    140
    #6
    How about in PHP?
     
    livingearth, May 19, 2008 IP
  7. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #7
    Maxmind have a C# API of their Country ( and Lite City I think ) ... search around on their site ...
     
    krakjoe, May 20, 2008 IP