?
Solved

Get User IP address

Posted on 2011-04-27
12
Medium Priority
?
356 Views
Last Modified: 2012-06-27
Hi,

I want to get the user IP address when they visit my site.  even if they have a firewall software application installed on their machine.

the code that I have now it display a number different then the IP address that I see when I run the cmd ipconfig /all
when I refresh my page the IP address Is: 12.176.249.232
but when I do a run cmd ipconfig then I see this IP: 10.25.120.194

So, I am not sure which one is correct??? and why I am getting two different one and
what's the code to get the correct IP address from the users machine???

here's my code:
      <CFIF #CGI.HTTP_X_Forwarded_For# EQ "">
            <CFSET ipaddress="#CGI.Remote_Addr#">
      <CFELSE>
            <CFSET ipaddress="#CGI.HTTP_X_Forwarded_For#">
      </CFIF>

<cfoutput>#ipaddress#</cfoutput>
 


0
Comment
Question by:lulu50
12 Comments
 
LVL 6

Expert Comment

by:cfEngineers
ID: 35475419
I believe that you are trying to get the machines IP address?
When your client is behind a firewall, the only IP address that will be shown is that of the firewall's outside address.
You would probably need some local java or vb on the clients machine to transmit the machine's internal IP address.

You can <cfdump  var="#cgi#"> to see all the information that is available to you.

I always use #cgi.remote_host# but that is my personal preference.
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 35475596

when I refresh my page the IP address Is: 12.176.249.232
but when I do a run cmd ipconfig then I see this IP: 10.25.120.194


The 10.25... address is your Internal IP address.   When inside a local area network (LAN) every computer is given an internal IP address.    The 12.176... number is the public or external address (Wide Area Network = WAN).   This is the one available over the internet.  You cannot get a user's internal IP address,  but if you could, there is nothing useful about it.  Internal addresses are not unique at all...   You will have MANY users with the same internal IP address.  

Internal addresses exist so that a company or local area of computers can manage a network without conflicting with the internet.  Imagine if every computer inside a company had to have a public IP address, the Public IPs would have to be three times longer !  

So, you should share what it is you're trying to accomplish and maybe we can help you with the best approach.  For example, you could use a unique session id, etc..

0
 

Author Comment

by:lulu50
ID: 35475817
gdemaria:

Thank you for making things clear to me this is great.  Let me tell you what I am trying to accomplish.
I have the main page called index.cfm
1. On index.cfm I have a list of states
exp:
New York
Connecticut
Michigan
Ohio

if the user visit my page for the first time that means this user is not a guest memeber of any state and a list
of all states will be displayed on index.cfm for the user to pick from.

if the user is not first time visitor then I should store something in my database from the user to know that they are
a guest member of a specific state.

if the user picked a specific state a detail information on that state will be displayed on a different page.

the whole idea is I don't want the user to every time visit my site to pick a state I want to store something in
my database to know that who ever used this machine is interested in this state so they will go directly to
a page that display information regarding the state the user selected.

Please, let me know if I confused you. (I have a broken english here)
0
[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

 
LVL 39

Expert Comment

by:gdemaria
ID: 35475960
I understand you very well, good job.

Your best bet is to use a cookie.   A cookie can indicate the user's preferred state and as long as the user returns to that computer, you will always know the state.

There are two ways to do this.   First, you can just save the state...

 <cfcookie name="preferState" value="CA">

The other option is to store a unique identifier for the user and have a matching one in the database for his/her state.

<cfcookie name="mySiteID"  value="329089874598743897435">

Associate that big number with the user's database record (preferably he will have a login or something associated with that so that if he/she goes to another computer, and he logs in, it will reset the cookie)


As far as their first visit, you can use locator code with the IP address to estimate their state and set it as the default.     That way when the user first visits your site, you could have their current state already selected, with the option of changing states, of course.    This code may cost money and may have a large database associated with it, so you may not want to do it, just an idea...

0
 

Author Comment

by:lulu50
ID: 35476111
gdemaria:

I have a question what do you think craigslist.org is using
if you visit the site for the first time then you will see a list of state and cities to select from
and based on the selection the site will take you to a page that display information about the selected city.

I tried to remove the cookies from my web browser than went back to craigslist.org site. The site
directed me to the state I already picked that means they are not using cookies.  because I removed mine and it still know what state I work with??

I want to use the same idea on my site.  HMMMM how did they do that???????
0
 

Author Comment

by:lulu50
ID: 35476116
I don't want to use cookies because the user can delete the cookies
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 35476209

They are probably using the IP location software I mentioned above.   You can do this too.  You take the IP address and call this software and get back their state.   There are lots of different things you can choose from.  Do some google searches on "IP address Location"  

But I would not be afraid to use cookies as well, really, how often does the typical user delete cookies?   And if they do, all they need to do is select the state again, not a big problem.

0
 

Author Comment

by:lulu50
ID: 35476324
gdemaria:

Please explain again and do you code example of IP location software
I like this idea and would like to use it on my site. any example code that
I can take a look at please.
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 1200 total points
ID: 35476412

I don't have an example, there are lots of options.  As I said, you may need to install a big database, you may need to purchase software, or maybe there is a web service to integrate with.

Here is an over view..

http://www.iplocation.net/

0
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 800 total points
ID: 35476546
(no points ...)

I'd just like to point out this kind of feature should be implemented so it degrades gracefully :) Whether you're using cookies or geo location software there are always cases where it doesn't work quite as expected (user disables cookies, wrong country detected, etc...).  So the site shouldn't break without it.  Also, not every body loves auto-geolocation.  A frequent complaint about google is it used to automatically route you to the google page of the country it *thinks* you're in.  Some people hate that.  So pre-selecting options is nice, but give users an option to correct things if they go wrong ;-)

Just my $0.02
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 35476633
Good Points agx...  


I suggest..

  On the user's first visit, set the location to the cookie, allow it to be modified by the user.

  Only check geo location if the cookie does not exist.
0
 

Author Closing Comment

by:lulu50
ID: 35476657
Thank you
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question