我正在使用grails,我想查找會話用戶的公共IP,以便我可以找到位置國家/地區。Grails查找會話用戶的公共IP地址
我使用:
InetAddress.getLocalHost().getHostAddress()
獲得IP,但問題是,它給我的私有IP即192.168.X.X這是沒有用的。
Thanx提前
我正在使用grails,我想查找會話用戶的公共IP,以便我可以找到位置國家/地區。Grails查找會話用戶的公共IP地址
我使用:
InetAddress.getLocalHost().getHostAddress()
獲得IP,但問題是,它給我的私有IP即192.168.X.X這是沒有用的。
Thanx提前
你只需要使用
InetAdress.getHostAddress()
但你可以只使用要求?
request.getRemoteAddr()
在同一會話中,您還可以使用
String ipAddr = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes())
.getRequest().getRemoteAddr();
查看 - > http://stackoverflow.com/questions/2140859/how-do-you-get-client-ip-address-in - 一個grails控制器 –
和http://stackoverflow.com/questions/7763338/how-to-find-out-connected-clients-ip-address-in-grails –