-2
InetAddress addr = java.net.InetAddress.getRemoteHost();
MyHost = addr.getHostName();
IPaddressString = addr.getHostAddress();

The above code returns the users local data being 127.0.0.1 and Localhost

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
AjayD3V
  • 9
  • 3
  • explain a little more what you are trying to do? do you have an active socket connection and you are attempting to get the IP address of the other end? – ewok Jul 20 '12 at 13:36
  • Question is unclear. When you say user do you mean client connecting to you ? – Siddharth Jul 20 '12 at 13:36

1 Answers1

0

1. If you want the IP of the remote user then you must have his Domain Name , if you want his Domain Name then you must have his IP.

2. Now i hope you are in LAN Environment, and have configured the IPs correctly.

3. Try assigning your PC with an ip suppose 192.168.20.1 and the other pc as 192.168.20.2

4. If you have Domain Name Associated with the remote pc, then you will get his Domain Name in return by using your code.

Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75