Grails Find Public Session User IP

I am using grails and I want to find the public IP address of the session user so that I can locate the country.

I use:

InetAddress.getLocalHost().getHostAddress() 

to get ip, but the problem is that it gives me a private ip ie 192.168.XX ip, which is useless.

Thanx in advance

+4
source share
1 answer

You just need to use

 InetAdress.getHostAddress() 

But can you just use the query?

 request.getRemoteAddr() 

Within a session, you can also use

 String ipAddr = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()) .getRequest().getRemoteAddr(); 
+6
source

Source: https://habr.com/ru/post/1381279/


All Articles