Question

I need to get the actual (not the gateway) ip address of my computer but all the solutions I have tried are returning the gateway IP address. For instance, all suggestions from this link Get the client IP address using PHP return the gateway address. Is there a way I can get the actual ip address (public) of my computer - either in php or java?

Was it helpful?

Solution

From the comments, it sounds like you want to create a unique identifier for each computer accessing the server. There is no one piece of information that you can get that will act as such an identifier, here's why:

IP Address The IP address that you can see is the public address, not the private address of a device behind a NAT'd router.

MAC Address The MAC address of each network card in each computer is unique, but that information is not available outside of the LAN segment.

You may be able to use a combination of pieces of information (like the IP address and user agent) to make an educated guess that a given request is coming from a unique user, but this would be a guess.. there's no way to be certain of it.

Use $_SERVER['REMOTE_ADDR'] to get the user's public address, and then $_SERVER['USER_AGENT'] to get their user agent. If the combination of these two are unique, then there's a good chance that the request is coming from a unique user.

Another way to do this would be to set a cookie that has a distant future expiration date, or a session ID. But this all depends on how long you need to keep track of the user, if you need to keep track of them after they've closed their browser and then later returned, etc. The only full-proof way is to create an account where they authenticate on your site.

OTHER TIPS

java's InetAddress class might be useful.

InetAddress IP=InetAddress.getLocalHost();
System.out.println("IP is := "+IP.getHostAddress());

Output: IP is := 10.100.95.228

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top