Our current system is receiving connections via sockets, and we need to determine the private IP of a connected client. Currently, we can easily access the public IP via connectingSocket.getInetAddress(), but what’s the best way to get the private address?
Thanks!
The simple answer is straightforward: you can’t.
The more complex answer: If you can control the way your clients connect to your java sockets (i.e. force them to use HTTP over a PROXY) you might have the proxy add that information to a special header. Or, if you use a proprietary protocol, you can encode the private IP on the protocol itself. But, there is no general way of obtaining that information. NAT simply makes the private IP address go away.