VB icon

Determine if the remote computer has a local or internet IP address

Email
Submitted on: 1/5/2015 6:47:00 PM
By: D. Jimmy (from psc cd)  
Level: Beginner
User Rating: By 6 Users
Compatibility: ASP (Active Server Pages), HTML
Views: 668
 
     if you have to determine if the remote computer visitor is local or external of your site and according to the case, for exemple redirect the user to the correct page...
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Determine if the remote computer has a local or internet IP address
' Description:if you have to determine if the remote computer visitor is local or external of your site and according to the case, for exemple redirect the user to the correct page...
' By: D. Jimmy(from psc cd)
'
' Assumes:This range of addresses shows constant IP of a LAN and never a computer will have this IP on internet (Private IP address ranges as specified in RFC 1918).
'10.0.0.0 -> 10.255.255.255
'172.16.0.0 -> 172.31.255.255
'192.168.0.0 -> 192.168.255.255
But don't forget : 
A Lan administrator can configure a LAN computer with an address IP out of the LAN range above.
With disabling "Allow Anonymous Access" on your application in IIS, you can know if the user of the remote computer was logged (and be on the LAN).
To do that get in String variable the logon with request.serverVariables.item("LOGON_USER").
An empty String means the user is not logged.
'**************************************

<HTML>
<BODY>
<%
dim ArrayIPLocalStart(2)
dim ArrayIPLocalEnd(2)
Dim ArrayIPClient
Dim IPClient 
dim blnLocal
Ipclient = Request.ServerVariables("REMOTE_ADDR")
Response.Write "Your IP is " & ipclient & "<BR>"
blnLocal = false
' These IP address are constant IP of a LAN
ArrayIPLocalStart(0) = "010.000.000.000" '"10.0.0.0"
ArrayIPLocalEnd(0) = "010.255.255.255" '"10.255.255.255"
ArrayIPLocalStart(1) = "172.016.000.000" '"172.16.0.0"
ArrayIPLocalEnd(1) = "172.031.255.255" '"172.31.255.255"
ArrayIPLocalStart(2) = "192.168.000.000" '"192.168.0.0"
ArrayIPLocalEnd(2) = "192.168.255.255" '"192.168.255.255"
ArrayIPClient = split(Ipclient,".")
' format the remote IP like constant LAN IP
for i = lbound(ArrayIPClient) to ubound(ArrayIPClient)
	ArrayIPClient(i) = string(3-len(ArrayIPClient(i) ),"0") & ArrayIPClient(i)
next
IPClient = join(ArrayIPClient,"")
if trim(ipclient) <> "" then
	for i = lbound(ArrayIPLocalStart) to ubound(ArrayIPLocalStart)
		ArrayIPLocalStart(i) = replace(ArrayIPLocalStart(i),".","")
		ArrayIPLocalEnd(i) = replace(ArrayIPLocalEnd(i),".","")
		if IPClient >= ArrayIPLocalStart(i) and IPClient =< ArrayIPLocalEnd(i) then
			blnLocal = true
			exit for
		End if
	next
end if
if blnLocal then
	Response.Write " And your computer has a local IP"
else
	Response.Write " And your computer has a internet IP"
End if
%>
</BODY>
</HTML>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.