Re: Client IP number?
Jon Nolan <[email protected]>
| Newsgroups | gmane.comp.web.webobjects.devel |
|---|---|
| Message-ID | <[email protected]> |
Denis Stanton wrote:
>
> On 23/02/2006, at 6:57 AM, Will Scheidegger wrote:
>
>> I have searched the web, archives and both wodev.com and wocode.com
>> for something that I thought would be very easy... How can I get the
>> IP# the request came from? I'm sure I've seen this before - maybe I
>> have already done it, but for now I cannot find a quick solution.
>
> Very roughly
>
> String hostString = context().request().headerForKey ("host");
> if (hostString == null)
> hostString = context().request().headerForKey ("http_host");
>
>
> I check both host and http_host in there because some build of apache
> changed this and I can't remember which is now current. (this is old
> code from a previous project)
>
> Remember that this host address is being inserted into the header by
> Apache. if you are working on WebObjects in developer mode you won't
> get a host address
Aren't host and/or http_host going to get you the server name?
I use this with very good results.
public static String remoteAddress(WORequest request) {
String remoteAddress =
(String)request.headerForKey("x-webobjects-remote-addr");
remoteAddress = (remoteAddress == null ?
(String)request.headerForKey("http_pc_remote_addr") : remoteAddress);
remoteAddress = (remoteAddress == null ?
(String)request.headerForKey("pc-remote-addr") : remoteAddress);
return (remoteAddress == null ?
(String)request.headerForKey("remote_addr") : remoteAddress);
}
Regards,
Jon
> _______________________________________________
> WebObjects-dev mailing list
> [email protected]
> http://www.omnigroup.com/mailman/listinfo/webobjects-dev
>