Re: request._remoteAddress() returns server address instead of client address
Re: request._remoteAddress() returns server address instead of client address
- Subject: Re: request._remoteAddress() returns server address instead of client address
- From: George Domurot <email@hidden>
- Date: Sat, 23 Oct 2010 12:34:09 -0700
Here's a snip of old code another WO developer shared with me many years back. It seems to work fine. Someone may want to chime in on a newer or better method of handling this.
/**
* Returns the IP address of the client.
* This should return accurate information whether in direct connect or
* webserver deployment mode.
*
* @return The IP address as a string.
*/
public String clientIPAddress(WORequest inRequest)
{
Object ipAddress = null;
if (inRequest != null)
{
ipAddress = inRequest.headerForKey("remote_addr");
if (ipAddress == null)
{
ipAddress = inRequest.headerForKey("remote_host");
if (ipAddress == null)
{
ipAddress = inRequest._remoteAddress();
if (ipAddress == null)
{
ipAddress = inRequest._originatingAddress();
if (ipAddress != null)
{
ipAddress = ((InetAddress) ipAddress).getHostAddress();
}
}
}
}
}
return ipAddress == null ? "<address unknown>" : ipAddress.toString();
}
-G
On Oct 23, 2010, at 9:33 AM, Farrukh Ijaz wrote:
> Hi,
>
> Shouldn't request._remoteAddress() return client's IP instead of server id? I'm debugging and in the header as well as using _remoteAddress(), I get the server address.
>
> How can I obtain client's address as part of WORequest?
>
> Thanks,
>
> Farrukh _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden