返回IP地址的代码:
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. ");
}
在测试它时,我的同一个系统运行它的服务器返回:
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
从网络中的不同系统检查时,它返回正确的值,但在开发环境中,它不返回我的系统IP地址或主机名。它正在返回一些未知的IP地址,我不知道。
请帮我修复此问题我想在访问我的应用程序时获取客户端IP地址和主机名。