0

Code for returning IP address:

String computerName = null;
String remoteAddress = request.getRemoteAddr();
System.out.println("remoteAddress: " + remoteAddress);
try{
  InetAddress inetAddress = InetAddress.getByName(remoteAddress);
  System.out.println("inetAddress: " + inetAddress);
  computerName = inetAddress.getHostName();
  System.out.println("Client Host Name :: " + computerName);
}catch (UnknownHostException e) {
  System.out.println("UnknownHostException detected in StartAction. ");
}

While testing it one my same system where server it running it is return:

remoteAddress: 0:0:0:0:0:0:0:1
inetAddress: /0:0:0:0:0:0:0:1
Client Host Name :: 0:0:0:0:0:0:0:1

When checking it from different system with in network it is returning correct value but on development environment it is not return my system IP address or host name. It is returning some unknown IP address, I don't know.

Please help me to fix this issue I want to get client IP address and host name while access my application.

Biffen
  • 6,249
  • 6
  • 28
  • 36

0 Answers0