Redirect based on IP address

windows

Guest
I have a page and I need to redirect users based on their IP address. For example, if a users IP address is in the 10.32.x.x range, I need them to go to a success page, if they do not have an IP in that range, I need them to go to a failure page.

I have been told this could be done with ASP, but ASP is not something I am familiar with. Can it be done, and if so, how?

thanks.if request.servervariables("HOST_USER") = "" then
response.rediect
end ifafterburn, I think I will need a little more help than that. I don't know anything about ASP but would like to learn. Fron the looks of the code you provided, is that the way you find out the IP from the client? If so, how do you then compare it to a rate of IP address, such as 10.32.0.0 thru 10.32.255.255?I did find this code, but not sure how to put it together (the array and the response.redirect()

Step 1 : Get the list of IPv4 ranges for the region of your choice (Look into <!-- w --><a class="postlink" href="http://www.apin.org">www.apin.org</a><!-- w --> for a beginning) and extract the ip's into a text file say call it ip.txt.

Step 2 : Get the IP address of the user and split it into an array with "." as the delimiter

Step 3 : Load the IP addresses from up.txt into a 2 dimensional array

Step 4 : Now for each IP range split the starting ip and ending ip into two arrays

Step 5 : Compare the corresponding numbers of the user ip array with those of the fromip and toip arrays

Step 6 : Repeat Step 4 thru Step 5 in a while loop till u reach the end of the array.

Now Go thru the snippet of code below and readthru the comments to understand it line by line.

<%
dim ipfromto(45,45)

yourip=split(request.ServerVariables("remote_addr"),".")


realpath=server.MapPath("./iponly.txt")


set myobj = server.CreateObject("scripting.filesystemobject")
set myfile = myobj.OpenTextFile(realpath)

i=1
while not myfile.atendofstream
line=myfile.readline
temp=split(line,"-")

ipfromto(i,1)=temp(0)
ipfromto(i,2)=temp(1)

i=i+1
wend
myfile.close


flag=false
j=1
While j< 46


'split the from-ip and to-ip based on "."
'fromip has the from ip address in four parts
'toip has the to ip address in four parts

fromip=split(ipfromto(j,1),".")
toip=split(ipfromto(j,2),".")
if yourip(0) > = fromip(0) and yourip(0) < = toip(0) then

if yourip(1) > = fromip(1) and yourip(1) < = toip(1) then

if yourip(2) > = fromip(2) and yourip(2) < = toip(2) then

if yourip(3) > = fromip(3) and yourip(3) < = toip(3) then

flag=true

end if

end if
end if

end if

if flag=true then
'Put your response.redirect() here
flag=false
else
'Put your response.redirect() here
end if

j=j+1
wend

%>
 
Back
Top