<分区>
我正在开发网络应用程序,我需要知道谁在访问我的网络应用程序,因为我需要运行我的应用程序的系统的 ip (ipv4) 地址。我正在使用 jsp 和 servlet 谁能帮我解决这个问题???
我尝试了下面的代码,但每次用户访问应用程序时它都会显示我的 ip 地址。但我需要客户端 ip (ipv4) 地址。
try {
Enumeration e = NetworkInterface.getNetworkInterfaces();
while(e.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface) e.nextElement();
System.out.println("Net interface: "+ni.getName());
Enumeration e2 = ni.getInetAddresses();
while (e2.hasMoreElements()){
InetAddress ip = (InetAddress) e2.nextElement();
System.out.println("IP address: "+ ip.toString());
}
}
}
catch (Exception e) {
e.printStackTrace();
}