Solved

Showing a users IP

Posted on 2004-10-01
7
1,284 Views
Last Modified: 2012-05-05
I am very new to coding and need some help.  I have numerous sites that show scripts on how to show a users IP address using scripts like;

><body>
<?
$ip = getenv('REMOTE_ADDR');
echo("<br/>Your IP Address is $ip");
?>
</body></html

the above works fine for internet users who are not using NAT or proxie.  I would like to be able to get both the Users PC IP address as well as the users gateway/proxie address.  I would like my site to show BOTH the REMOTE_ADDR and the USERS PC ADDRESS.

Any help would be very much appreciated.

Thanks
0
Comment
Question by:broadspoke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 12204717
That isn't possible. If the user is behind a NAT firewall or proxy, then you can not get their IP address. That is one of the biggest advantages to using NAT. Otherwise, if you could still get a user's -private- IP address, then it wouldn't be private, and it wouldn't be safe.

Users will only have one IP address and that will be either their computer or their firewall / proxy. That IP address is available in the REMOTE_ADDR variable like you've been using. Sorry!
0
 
LVL 3

Expert Comment

by:Drift3r
ID: 12205571
Hum ... it depends on the configuration ... the proxy problem can be addressed ...

check this ... I already answered a question addressing this problem ...

http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20834727.html

It is not possible to get the address of everyone nevertheless ... it depends on configurations of the firewalls proxys etc which are beyond your control.
0
 

Author Comment

by:broadspoke
ID: 12205895
Thanks for the comments.  But, I think there has to be a way to do this.  I found and example on line that uses a Java Applet and it works.  I know because I am behind a NAT'd network.  I do not understand how to make a Java Applet and prefer PHP for most of my code.  

If y9ou can offfer some help I would really be grateful.

Site that works. http://www.u.arizona.edu/~trw/games/nat_or_not.php

Thanks

Broadspoke
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 3

Accepted Solution

by:
Drift3r earned 50 total points
ID: 12206049
Well ... that works with java because java runs in the client side and has local access and Network libraries to manipulate that kind of info... you'll never do it with PHP because it runs on the server side ... not even with javascript you can get it unless you use javascript to call java ... like in this example:

http://sharkysoft.com/tutorials/jsa/content/040.html

or this one:

http://javascript.internet.com/user-details/ip.html

It's still a long shot as I think the user has to have Java installed ... not everybody has ... so there's really no sure way to get what you want ...

Either way ... Why do you want a nat address? What's the use? If he's on DHCP next time he'll probably have a different IP. Even if he has the same IP ... about 10 million other people can have the same IP ... (as it is a private IP) ... what's the use?
0
 
LVL 3

Expert Comment

by:Drift3r
ID: 12206053
Just to give you an example ... my machine appears in that applet like this:


initializing...
Your local IP address is  10.0.0.3
Your global IP address is <?=$REMOTE_ADDR?>
It would appear that your machine does use NAT.
Your machine has an IP address of 10.0.0.3,
but your browser connected to this page from <?=$REMOTE_ADDR?>!
You are in the private range: 10.0.0.0 - 10.255.255.255 (10/8 prefix)

See the <?=$REMOTE_ADDR?> ... it can't get that ...
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12206608
Maybe you should try use this get IP function

This function checks if user is coming behind proxy server and also tries to get the real IP
Note that getenv() function doesn't work when PHP is running as ISAPI module

/**********************************************************/

function ip_address()
{

      if (getenv('HTTP_CLIENT_IP'))
                {
             $ip = getenv('HTTP_CLIENT_IP');
      }
      elseif (getenv('HTTP_X_FORWARDED_FOR'))
                {
            $ip = getenv('HTTP_X_FORWARDED_FOR');
      }
      elseif (getenv('HTTP_X_FORWARDED'))
                {
            $ip = getenv('HTTP_X_FORWARDED');
      }
      elseif (getenv('HTTP_FORWARDED_FOR'))
                {
            $ip = getenv('HTTP_FORWARDED_FOR');
      }
      elseif (getenv('HTTP_FORWARDED'))
                {
            $ip = getenv('HTTP_FORWARDED');
      }
      else
                {
            $ip = $_SERVER['REMOTE_ADDR'];
       }
      
                return $ip;
}

/***************************************************************/

j311y :)
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 12210731
Everyone else has pretty much summed it up. Like Drifter said, the Java applet works because its client side portion has access to that information. But as soon as the workstation sends a request through a proxy/firewall with NAT, it loses the internal IP and it's up to the firewall or proxy to provide that information (and most don't). I don't mean to be a downer, but that's just one issue that you have to work with when dealing with server-side programming.

If you have control over the firewall or proxy, then that's a different story, since you could program the device/software to provide that IP, but chances are that that's not your situation.

- J
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

690 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