Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > ASP - Only allow access via specific IP address

Reply
Thread Tools

ASP - Only allow access via specific IP address

 
 
Jez
Guest
Posts: n/a
 
      10-27-2008
I'm trying to work this out..

But I'm a little stuck...

<%
'declare variables
Dim sIP1
Dim sIP2
Dim sIP3

'assign our APPROVED IP addresses (all extrenal addresses)
sIP1 = "xxx.xxx.xxx.xxx"
sIP2 = "xxx.xxx.xxx.xxx"
sIP3 = "xxx.xxx.xxx.xxx"

'retrieve the visitors IP address
sIP = Request.ServerVariables("REMOTE_ADDR")

'check if IP address matches any of the approved IPs
response.write sIP
If sIP <> sIP1 OR sIP <> sIP2 OR sIP <> sIP3 Then
Response.Redirect "http://www.google.com"
else
response.write "HELLO & WELCOME"
End If
%>

How do I do the IF statement ?? if sIP is anything other that sIP1 or
sIP2 or sIP3 then ???
Thanks
 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      10-27-2008
Jez wrote:
> I'm trying to work this out..
>
> But I'm a little stuck...
>
> <%
> 'declare variables
> Dim sIP1
> Dim sIP2
> Dim sIP3
>
> 'assign our APPROVED IP addresses (all extrenal addresses)
> sIP1 = "xxx.xxx.xxx.xxx"
> sIP2 = "xxx.xxx.xxx.xxx"
> sIP3 = "xxx.xxx.xxx.xxx"
>
> 'retrieve the visitors IP address
> sIP = Request.ServerVariables("REMOTE_ADDR")
>
> 'check if IP address matches any of the approved IPs
> response.write sIP
> If sIP <> sIP1 OR sIP <> sIP2 OR sIP <> sIP3 Then
> Response.Redirect "http://www.google.com"
> else
> response.write "HELLO & WELCOME"
> End If
> %>
>
> How do I do the IF statement ?? if sIP is anything other that sIP1 or
> sIP2 or sIP3 then ???
> Thanks


OR - returns true if one of the logical expressions is true. sIP cannot be
equal to all three approved addresses at the same time can it? No. Which
means the OR expression will always return true, won't it? You need to use
AND instead of OR if you want to use inequality tests.
If sIP <> sIP1 AND sIP <> sIP2 AND sIP <> sIP3 Then
This expression will only return True if all three of the inequalities are
true.

Alternatively, you could turn it around:
If sIP = sIP1 OR sIP = sIP2 OR sIP = sIP3 Then
response.write "HELLO & WELCOME"
else
Response.Redirect "http://www.google.com"
End If

Or use Select Case, or InStr():

Dim s:s="," & sIP1 & "," & sIP2 & "," & sIP3 & ","
If Instr(s, "," & sIP & ",")>0 then

response.write "HELLO & WELCOME"
else
Response.Redirect "http://www.google.com"
End If

--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: PIX 506 VPN allow access only to specific subnets based on username Walter Roberson Cisco 1 01-25-2006 03:10 AM
PIX 506 VPN allow access only to specific subnets based on username John Mason Jr Cisco 0 01-24-2006 12:00 AM
How to restrict direct access to JSP files, only allow access via servlet? Anan Java 8 12-08-2004 11:16 PM
How do I let people access the internet via an access point but not allow them access to my network yar Wireless Networking 4 09-21-2004 03:48 AM
Location element in the Web.config file. Allow System Admin whole directory, allow others specific page Ryan Taylor ASP .Net Security 1 09-09-2004 06:52 PM



Advertisments