Forums

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

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Satish Bejgum
Client IP Address
June 27, 2009 2:46 AM
Answer

Satish Bejgum

Rank: Junior Member

Posts: 45

Join Date: November 5, 2008

Recent Posts

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
June 27, 2009 10:30 AM
Answer

Brian Chan

LIFERAY STAFF

Rank: Liferay Master

Posts: 751

Join Date: August 4, 2004

Recent Posts

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
June 29, 2009 5:37 AM
Answer

Satish Bejgum

Rank: Junior Member

Posts: 45

Join Date: November 5, 2008

Recent Posts

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
February 23, 2012 10:12 PM
Answer

Mazhar Alam

Rank: Regular Member

Posts: 188

Join Date: November 25, 2011

Recent Posts

Thanks its working fine for me.
siddhant jain
RE: Client IP Address
April 2, 2013 12:15 AM
Answer

siddhant jain

Rank: Junior Member

Posts: 53

Join Date: March 19, 2013

Recent Posts

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
April 2, 2013 5:35 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7008

Join Date: September 1, 2006

Recent Posts

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