Print Page | Close Window

Blocking access to website

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Web Design Discussion
Forum Description: Discussion on web design and development subjects.
URL: https://forums.webwiz.net/forum_posts.asp?TID=5990
Printed Date: 29 March 2026 at 2:58pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Blocking access to website
Posted By: cfaulk
Subject: Blocking access to website
Date Posted: 26 September 2003 at 8:08am
How do I block certain IP addresses from accessing my website?



Replies:
Posted By: KCWebMonkey
Date Posted: 26 September 2003 at 8:24am
See this thread for an example: http://forums.webwiz.net/forum_posts.asp?TID=4967 - http://forums.webwiz.net/forum_posts.asp?TID=4967


Posted By: fernan82
Date Posted: 29 September 2003 at 10:36pm
Anyone has a formula to ban IP ranges?, not like 192.168.1.* but like 192.168.1.1-192.168.231.255...... I gotta make one and that kind of stuff gives me headaches..


Posted By: Gullanian
Date Posted: 30 September 2003 at 9:27am

192.168.1.1 to
192.168.231.255 huh?

ill post in a sec a lil code for ya

 



Posted By: Gullanian
Date Posted: 30 September 2003 at 9:43am

ITs pretty crude, and also only works if the IP address has four sections each 3 digits long, so its a got structure to build up on:


<%
  Dim strMaxRange 'Upper bound IP blocking range
  Dim strMinRange 'Lower bound IP blocking range
  Dim intLoop 'Loop counter
  Dim strCurrentIP 'Visitors IP address
  Dim intSectionMin 'Lower bound IP address slice
  Dim intSectionMax 'Upper bound IP address slice
  Dim intVisIPSlice 'Slice of visitors IP
  Dim blnIsIPOK 'Is the IP address ok so far

  'Set variables
  strMinRange = "000.000.000.000"
  strMaxRange = "255.255.255.255"
  intLoop = 0
  strCurrentIP = Request.ServerVariables("REMOTE_ADDR")
  blnIsIPOK = True

  'Take out the dots
  strMinRange = Replace(strMinRange,".","")
  strMaxRange = Replace(strMaxRange,".","")
  strCurrentIP = Replace(strCurrentIP,".","")

  'Loop through all the sections
  Do until intLoop = 4 or blnIsIPOK = False
    intLoop = intLoop + 1
    'Get the slices of the IP range
    intSectionMin = mid(strMinRange,intLoop*3,3)
    intSectionMax = mid(strMaxRange,intLoop*3,3)
    intVisIPSlice = mid(strCurrentIP,intLoop*3,3)

    'If the slice falls out of range IP is blocked
    IF intVisIPSlice
< intSectionMax AND intVisIPSlice > intSectionMin then
      blnIsIPOK = False
    End if
  Loop

  Select case blnIsIPOK
    Case True
      Response.write("IP Address of current visitor is not in the blocked range")
    Case False
      Response.write("IP Address of current visitor is in the blocked range")
  End select

  Response.write("<BR><BR>Visitors current IP Address is " & Request.ServerVariables("REMOTE_ADDR"))
%>




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net