View Full Version : User from internet or intranet?
codefox
12-16-2002, 09:17 AM
I'd like to check if the user accessing my site is from the internet or from the intranet, based on which I display different messages in a page. I propose to check the REMOTE_ADDR server variable to determine the user. But I'm not sure if checking if the REMOTE_ADDR = 127.x.x.x or 10.x.x.x would suffice. Thus if the first hex part of the ip address is 10 then he's from a lan, or if t's 127, it's the local machine. Otherwise he's from internet. Would this be a foolproof way of determining where the user is from? Just forgot my TCP/IP lessons :D.
Leeus
12-16-2002, 02:17 PM
No because I'm at work now and we being an ISP use public statics for our internal network so it is never foolproof!
oracleguy
12-17-2002, 12:57 AM
It would work if your network had a Class B or C IP addressing scheme. Because on the internet all the ISPs have to use Class A.
Because if it was Class B or C then you could just take the first octet and see if it was above or equal to 128.
codefox
12-17-2002, 05:30 AM
Thanks leeus and oracleguy. Now I know that if the first octet is any of 0 thru 127, it's a class A address. But if the IP address has 127 as the first octet does it refer to the local machine or is it just 127.0.0.1 that refers to the local machine? Also, can I be sure that if the IP address is a class A address, it's an Internet address?
codefox
12-17-2002, 05:36 AM
Here's the function I use to check if the IP is an Internet IP
Function IsUserFromInternet(ByVal ip)
Dim iFirstOctet, bUserFromInternet
iFirstOctet = Left(ip, ())
bUserFromInternet = False
If iFirstOctet > 0 And iFirstOctet < 127 Then
IsUserFromInternet = True
End If
IsUserFromInternet = bUserFromInternet
End Function
Is this ok?
codefox
12-17-2002, 05:39 AM
Oops, iFirstOctet = Left(ip, Instr(1, ip, ".")). I forgot to include InStr() :D
codefox
12-17-2002, 06:16 AM
Since I'm beind a firewall, my IP address starts with 10. Here's the function I used to check if a user is from the internet.
Function IsUserFromInternet(ByVal ip)
Dim iFirstOctet, bUserFromInternet
iFirstOctet = CInt(Left(ip, Instr(1, ip, ".")))
bUserFromInternet = False
' Class A range: 1 - 126
' There are special reserved IP numbers that are specifically dedicated to
' LANs behind a proxy server or that are not connected to the Internet at
' all. These are reserved numbers that are NEVER used as publicly
' accessible addresses on the Internet. The IP number sequences are:
' 10.0.0.0 (netmask 255.0.0.0). Any IP# starting with 10. is a fake.
If iFirstOctet > 0 And iFirstOctet < 127 And iFirstOctet <> 10 Then
IsUserFromInternet = True
End If
IsUserFromInternet = bUserFromInternet
End Function
whammy
12-18-2002, 12:13 AM
Another way...
<%
Function IsUserFromInternet(ByVal ip)
Dim iparray
iparray = Split(ip,".")
IsUserFromInternet = (iparray(0) = "10")
End Function
Dim ip
ip = Request.ServerVariables("REMOTE_ADDR")
Response.Write(ip & vbCrLf)
Response.Write(IsUserFromInternet(Request.ServerVariables("REMOTE_ADDR")) & vbCrLf)
%>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.