Forum

Accueil » Liferay Portal » English » 2. Using Liferay » General

Vue combinée Vue Plate Arborescence
Sujets [ Précédent | Suivant ]
toggle
Satish Bejgum
Client IP Address
27 juin 2009 02:46
Réponse

Satish Bejgum

Rang: Junior Member

Publications: 45

Date d'inscription: 5 novembre 2008

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
Brian Chan
RE: Client IP Address
27 juin 2009 10:30
Réponse

Brian Chan

LIFERAY STAFF

Rang: Liferay Master

Publications: 751

Date d'inscription: 4 août 2004

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 emoticon
Satish Bejgum
RE: Client IP Address
29 juin 2009 05:37
Réponse

Satish Bejgum

Rang: Junior Member

Publications: 45

Date d'inscription: 5 novembre 2008

Publications Récentes

I'm able to get the client IP by using
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
RE: Client IP Address
23 février 2012 22:12
Réponse

Mazhar Alam

Rang: Regular Member

Publications: 188

Date d'inscription: 25 novembre 2011

Publications Récentes

Thanks its working fine for me.
siddhant jain
RE: Client IP Address
2 avril 2013 00:15
Réponse

siddhant jain

Rang: Junior Member

Publications: 57

Date d'inscription: 19 mars 2013

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???
David H Nebinger
RE: Client IP Address
2 avril 2013 05:35
Réponse

David H Nebinger

Rang: Liferay Legend

Publications: 7849

Date d'inscription: 1 septembre 2006

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").