I currently have an IP address checking system in place to block IP's that abuse my querystrings. Most of these are from outside the US.
My question is:
How can I block everyone but US IP addresses? I don't know if i can use somthing like this "215.*.*.*" or "215*"' and it work.
Thanks
Jason
2 4014 - response.write request.serverVariables("remote_addr")
-
response.write request.serverVariables("remote_host")
I can't remember what happens when you try to connect thru a proxy, and I've never bothered to check which IP addresses belong to which areas, but I understand that isn't hard to look up. So you could do something like this: - if left(request.serverVariables("remote_addr"), 3) = "255" then
-
response,.write "Welcome to my site"
-
else
-
response.write "see you later, bozo."
-
end if
Download IP2Country.zip from here and extract it.
Make this vbs script and edit it to allow only US country code or whatever country codes you wish to allow. Then execute the file. -
'RemoveJunk.vbs
-
Const Countries2Keep = "US,CA,AU" 'Country codes to allow access
-
Const ForReading = 1
-
Const ForWriting = 2
-
-
Dim sAppPath, sFileIn, sFileOut
-
sAppPath = Mid(Wscript.ScriptFullName, 1, InStrRev(Wscript.ScriptFullName, "\"))
-
sFileIn=sAppPath & "iptocountry.csv"
-
sFileOut=sAppPath & "CountryIPs.csv"
-
-
call TrimJunk(sFileIn, sFileOut)
-
-
sub TrimJunk(from_name, to_name)
-
Dim sTemp, arTemp, LineNo
-
Dim fFrom, fTo
-
Dim fso
-
set fso = CreateObject("Scripting.FileSystemObject")
-
Set fFrom = fso.OpenTextFile(from_name, ForReading)
-
Set fTo = fso.CreateTextFile(to_name, True)
-
-
fTo.WriteLine "StartIP" & vbtab & "EndIP" & vbTab & "CountryCode"
-
-
Do Until fFrom.AtEndOfStream
-
sTemp = replace(fFrom.ReadLine,"""","")
-
LineNo=LineNo+1
-
If sTemp <> empty and left(sTemp, 1) <> "#" Then
-
' write line to combined csv file
-
arTemp=split(stemp,",")
-
if ubound(arTemp) <> 6 then
-
wscript.echo "Error parsing line (" & LineNo & ") too many commas."
-
else
-
if IsGoodCountry(arTemp(4)) then
-
fTo.WriteLine arTemp(0) & vbtab & _
-
arTemp(1) & vbtab & _
-
arTemp(4)
-
end if
-
end if
-
End If
-
Loop
-
-
fFrom.close
-
fTo.close
-
End sub
-
-
function IsGoodCountry(sCC)
-
Dim arGoodCCs, iCC
-
arGoodCCs=split(Countries2Keep,",")
-
for iCC = 0 to ubound(arGoodCCs)
-
if arGoodCCs(iCC) = sCC then
-
IsGoodCountry=True
-
exit for
-
end if
-
next 'iCC
-
end function
Import the "CountryIPs.csv" output file created by the script into your database.
Use this ASP page to test. -
-
<%
-
'IPCheck.asp
-
'ASP File (need to add your own DB connection string)
-
-
Dim rs
-
Dim cn
-
'Create database connection object
-
set cn = server.CreateObject("adodb.connection")
-
'Create recordset object
-
set rs = server.CreateObject("adodb.recordset")
-
'Open database connection
-
cn.Open strCon 'use your DB connection string here
-
-
call WritePage
-
'End
-
-
-
sub WritePage
-
dim VisitorIP
-
VisitorIP=Request.ServerVariables("Remote_Addr")
-
-
strSQL="Select StartIP, EndIP, CountryCode from CountryIPs.dbo.IPs WHERE " & IPToNum(VisitorIP) & " BETWEEN StartIP AND EndIP"
-
-
rs.Open strSQL, cn, adOpenForwardOnly, adLockReadOnly
-
if rs.EOF then
-
Response.Write "Access Denied, If you are in the United States please <a href=""mailto:Webmaster@mydomain.com"">Let us know</a> you are having this error."
-
else
-
Response.Write "Access Granted: " & VisitorIP & " is between " & Num2IP(rs("startip")) & " and " & Num2IP(rs("endip")) & " assigned to " & rs("CountryCode")
-
end if
-
end sub
-
-
-
-
'IPToNum() function - turns a textual IP address into a 32-bit number
-
Function IPToNum(strIP)
-
Dim numOctetsArray
-
Dim i
-
numOctetsArray = Split(strIP,".")
-
-
'sanity checks
-
If UBound(numOctetsArray) <> 3 Then
-
'oops = wrong number of octets
-
IPToNum = -1
-
Exit Function
-
End If
-
-
For i = 0 to 3
-
If Not IsNumeric(numOctetsArray(i)) Then
-
'oops - not an IP address
-
IPToNum = -2
-
Exit Function
-
End If
-
-
If numOctetsArray(i) > 254 Then
-
'oops - octet out of range
-
IPToNum = -3
-
Exit Function
-
End If
-
Next
-
-
'now compile a number
-
IPToNum = numOctetsArray(0) * (2^24)
-
IPToNum = IPToNum + numOctetsArray(1) * (2^16)
-
IPToNum = IPToNum + numOctetsArray(2) * (2^8)
-
IPToNum = IPToNum + numOctetsArray(3)
-
End Function
-
-
Function Num2Ip(ByVal Num)
-
'Presets the return of function
-
Num2Ip = Null
-
Num=clng(num)
-
'Evaluates the parameter
-
If Len(Num) = 0 Then Exit Function
-
If Not IsNumeric(Num) Then Exit Function
-
Num = CDbl(Num)
-
If Num < 0 Or Num > 4294967295 Then Exit Function
-
-
'Starts the calc
-
Num = Num / 16777216
-
Num2Ip = Fix(Num) & "."
-
Num = ((Num - Fix(Num)) * 16777216) / 65536
-
Num2Ip = Num2Ip & Fix(Num) & "."
-
Num = ((Num - Fix(Num)) * 65536) / 256
-
Num2Ip = Num2Ip & Fix(Num) & "."
-
Num = (Num - Fix(Num)) * 256
-
-
'Returns the sum
-
Num2Ip = Num2Ip & Fix(Num)
-
End Function
-
-
%>
You will want to update your database occasionally.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: jtd |
last post by:
Hi all,
I'm using asyncore to download a large list of web pages, and I've
noticed dispatcher.connect blocks for some hosts. I was under the
impression that non-blocking sockets do not block on...
|
by: F Magnell |
last post by:
How do I block referring sites in ASP using VBScript?
Like blocking referrer's from:
192.025.215.001
and
altavista.com
|
by: Hal |
last post by:
I am experiencing blocking problems on SQL Server 2000, SP3a. I have
read the posts and set up a job SQL agent to report on these
occurences I save the results to a table before executing an sp to...
|
by: David Sworder |
last post by:
This message was already cross-posted to C# and ADO.NET, but I forgot to
post to this "general" group... sorry about that. It just occured to me
after my first post that the "general" group readers...
|
by: him |
last post by:
All the world aside, Iran alone and on itself has blocked half of the
internet, including many "moral" and useful websites, mainly because of its
medieval policies. The level of filtering has...
|
by: Mario |
last post by:
Hello,
I couldn't find a solution to the following problem (tried
google and dejanews), maybe I'm using the wrong keywords?
Is there a way to open a file (a linux fifo pipe actually) in...
|
by: Michi Henning |
last post by:
Hi,
I'm using a non-blocking connect to connect to a server.
Works fine -- the server gets and accepts the connection.
However, once the connection is established, I cannot
retrieve either the...
|
by: =?ISO-8859-1?Q?Fran=E7oise_Debat?= |
last post by:
Hello,
I wonder if anybody can help. I have an IP blocking script which
displays a blank screen if an IP is detected from a list in an external
file. The problem is, the script only reads the...
|
by: puzzlecracker |
last post by:
is it even possible or/and there is a better alternative to accept
input in a nonblocking manner?
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |