Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get ip behind NAT using php?

Tags:

php

lamp

wamp

Is it possible to retrieve IP behind NAT in PHP? I am using $_SERVER["REMOTE_ADDR"] for getting IP address of the client. It's not giving exact IP address of the client which is in behind NAT.

like image 348
Javad Shareef Avatar asked Dec 21 '11 08:12

Javad Shareef


People also ask

How can we get IP address of a client in PHP?

Using getenv() function: To get the IP Address,we use getenv(“REMOTE_ADDR”) command. The getenv() function in PHP is used for retrieval of values of an environment variable in PHP.

How do you know if I am behind a NAT?

Go to www.whatismyip.com. If the IP it shows is different from the IP of your NIC, you're behind a NAT. If by NAT you mean any NAT including a WIFI router for example click the windows button, type cmd, click on command prompt, type in ipconfig and press enter, see what it says to the right of "IPv4 Address".

How do I find the IP address of a user?

On the command prompt screen, type the words “ping host address,” where “host address” equals the address of the website you're looking to trace, and hit Enter. For example, if you want to find the IP address of Facebook, you would type the words “ping www.facebook.com” and then press enter.


2 Answers

It is not possible to get the IP behind a NAT using HTTP and php.

like image 136
fyr Avatar answered Sep 28 '22 12:09

fyr


Nope, not possible. NAT means Network Address Translation - the IP address of the packets is rewritten at the NAT device, so the public IP address is the only one, as far as your server knows.

However, you can employ some tricks - such as checking for the internal IP address using a Java Applet. See this: Get the correct local IP address from java applet

like image 25
Piskvor left the building Avatar answered Sep 28 '22 11:09

Piskvor left the building