Reputation: 23
How can I get the ip address of users who connect to my site located on my server using apache? I only get the ip address of my server.
protected void getUserIp (){
try {
InetAddress ia = InetAddress.getLocalHost();
String ipAddr = ia.getHostAddress();
String hostName = ia.getHostName();
log.debug("Local IP: " + ipAddr + "and" + "HOST: " + hostName);
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
Upvotes: 1
Views: 109
Reputation: 181
Is this code running inside a Spring controller ?
You can add a HttpServletRequest request
argument to the controller method, which Spring will inject for you, and then you can do request.getRemoteAddr()
The HttpServletRequest
object is coming from the Apache Tomcat
Upvotes: 1
Reputation: 36103
You could try:
UI.getCurrent().getSession().getBrowser().getAddress()
Upvotes: 1