Forums de discussion
Client IP Address
satish bejgum, modifié il y a 14 années.
Client IP Address
Junior Member Publications: 44 Date d'inscription: 05/11/08 Publications récentes
Hello All,
How do i get Client IP Address in JSP?
I have tried using request.getRemoteAddr() but its returning null.
Can anyone suggest how do i get client ip address?
Thanks
How do i get Client IP Address in JSP?
I have tried using request.getRemoteAddr() but its returning null.
Can anyone suggest how do i get client ip address?
Thanks
Brian Chan, modifié il y a 14 années.
RE: Client IP Address
Liferay Master Publications: 753 Date d'inscription: 05/08/04 Publications récentes
Try:
com.liferay.portal.util.PortalUtil.getHttpServletRequest(renderRequest).getRemoteAddr()
The spec forces us to make it so that the request.getRemoteAddr() returns null, but the method above will return to you the real HttpServletRequest. Be careful what you do with that object though
com.liferay.portal.util.PortalUtil.getHttpServletRequest(renderRequest).getRemoteAddr()
The spec forces us to make it so that the request.getRemoteAddr() returns null, but the method above will return to you the real HttpServletRequest. Be careful what you do with that object though
satish bejgum, modifié il y a 14 années.
RE: Client IP Address
Junior Member Publications: 44 Date d'inscription: 05/11/08 Publications récentes
I'm able to get the client IP by using
but is there any harm leaving that object alone? if so, how do i get out of it?
Thanks
com.liferay.portal.util.PortalUtil.getHttpServletRequest(renderRequest).getRemoteAddr()
but is there any harm leaving that object alone? if so, how do i get out of it?
Thanks
Mazhar Alam, modifié il y a 12 années.
RE: Client IP Address
Regular Member Publications: 191 Date d'inscription: 25/11/11 Publications récentes
Thanks its working fine for me.
siddhant jain, modifié il y a 11 années.
RE: Client IP Address
Junior Member Publications: 69 Date d'inscription: 19/03/13 Publications récentes
com.liferay.portal.util.PortalUtil.getHttpServletRequest(renderRequest).getRemoteAddr()
this method is returning the proxy address
i have tried
.getHeader("X-FORWARDED-FOR");
but it is also returning null.
how to get the ip address of originating client and not of its proxy???
this method is returning the proxy address
i have tried
.getHeader("X-FORWARDED-FOR");
but it is also returning null.
how to get the ip address of originating client and not of its proxy???
David H Nebinger, modifié il y a 11 années.
RE: Client IP Address
Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
You have to find out what header the proxy is setting for the originating client ip address.
Then use PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest)).getHeader("my-proxy-header").
Then use PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest)).getHeader("my-proxy-header").
Jobin Mathew, modifié il y a 9 années.
RE: Client IP Address
Junior Member Publications: 77 Date d'inscription: 04/07/14 Publications récentesDavid H Nebinger:
You have to find out what header the proxy is setting for the originating client ip address.
Then use PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest)).getHeader("my-proxy-header").
FacesContext facesContext = FacesContext.getCurrentInstance();
PortletRequest portletRequest = (PortletRequest) facesContext.getExternalContext().getRequest();
HttpServletRequest request = PortalUtil.getHttpServletRequest(portletRequest);
HttpServletRequest originalServletRequest = PortalUtil.getOriginalServletRequest(request);
String ipAddress=originalServletRequest.getHeader("x-forwarded-for");
it works for me .. it it correct?
David H Nebinger, modifié il y a 9 années.
RE: Client IP Address
Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
Sure. It all depends upon the header used by your proxy, and if this is working for you then you've found the right one!
Jobin Mathew, modifié il y a 9 années.
RE: Client IP Address
Junior Member Publications: 77 Date d'inscription: 04/07/14 Publications récentes
Thanks
ronak vora, modifié il y a 3 années.
RE: Client IP Address
Junior Member Publications: 25 Date d'inscription: 26/09/18 Publications récentes
Yes it's working fine for me,
but
1. when i tries to get client ip from redirect.url.ips.allowed 103.251.219.xxx it's getting my default IP address instead of client ip address.
2. When i tries to get client ip from 192.168.2.xxx it's getting proper client ip address ?
anyone has solution for this?
Into portal-ext.properties setted both url as well
redirect.url.ips.allowed=192.168.2.xxx, 103.251.219.xxx
Thanks in advance
Ronak Vora
but
1. when i tries to get client ip from redirect.url.ips.allowed 103.251.219.xxx it's getting my default IP address instead of client ip address.
2. When i tries to get client ip from 192.168.2.xxx it's getting proper client ip address ?
anyone has solution for this?
Into portal-ext.properties setted both url as well
redirect.url.ips.allowed=192.168.2.xxx, 103.251.219.xxx
Thanks in advance
Ronak Vora