Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Get IP tomcat server (http://www.velocityreviews.com/forums/t598125-get-ip-tomcat-server.html)

Sylvain 03-12-2008 02:38 PM

Get IP tomcat server
 
Hi !

I am using Tomcat and i would like to get the host IP from the
servletContext object. Does anybody know how to get it ?

Thank you for your help

Best regards

Sylvain Caillet



Arne Vajh°j 03-13-2008 02:47 AM

Re: Get IP tomcat server
 
Sylvain wrote:
> I am using Tomcat and i would like to get the host IP from the
> servletContext object. Does anybody know how to get it ?


request.getLocalAddr()

Arne



Sylvain 03-13-2008 08:23 AM

Re: Get IP tomcat server
 
Hi !

Thank you Arne for this answer but i would like to get this data at the
start of the context not at the first request. That's why i was looking for
getting the server's IP with the servletContext.

Best regards

Sylvain


"Arne Vajh°j" <arne@vajhoej.dk> a Úcrit dans le message de news:
47d895c2$0$90262$14726298@news.sunsite.dk...
> Sylvain wrote:
>> I am using Tomcat and i would like to get the host IP from the
>> servletContext object. Does anybody know how to get it ?

>
> request.getLocalAddr()
>
> Arne
>
>




Sylvain 03-13-2008 10:42 AM

Re: Get IP tomcat server
 
I have done it by getting the output stream of a IFCONFIG command shell and
parsing it to find the first IP with regular expressions. It works fine.

Thank you all

Sylvain


"Sylvain" <s.caillet_nospam@free.fr> a Úcrit dans le message de news:
47d8e476$0$894$ba4acef3@news.orange.fr...
> Hi !
>
> Thank you Arne for this answer but i would like to get this data at the
> start of the context not at the first request. That's why i was looking
> for getting the server's IP with the servletContext.
>
> Best regards
>
> Sylvain
>
>
> "Arne Vajh°j" <arne@vajhoej.dk> a Úcrit dans le message de news:
> 47d895c2$0$90262$14726298@news.sunsite.dk...
>> Sylvain wrote:
>>> I am using Tomcat and i would like to get the host IP from the
>>> servletContext object. Does anybody know how to get it ?

>>
>> request.getLocalAddr()
>>
>> Arne
>>
>>

>
>




Nigel Wade 03-13-2008 12:17 PM

Re: Get IP tomcat server
 
Sylvain wrote:

> I have done it by getting the output stream of a IFCONFIG command shell and
> parsing it to find the first IP with regular expressions. It works fine.
>


Does the static method:
NetworkInterface.getNetworkInterfaces()
not work in a servlet? It should provide the same information as ifconfig, but
without the overhead of creating a Process and parsing the output. Also,
parsing the output of ifconfig is almost certainly not portable.

Your original request was to extract the information from the servletContext,
which AFIAK is not possible.

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555

Arne Vajh°j 03-14-2008 12:52 AM

Re: Get IP tomcat server
 
Sylvain wrote:
> Thank you Arne for this answer but i would like to get this data at the
> start of the context not at the first request. That's why i was looking for
> getting the server's IP with the servletContext.


That is not necessarily unique.

You can lookup all the IP addresses on the system. And
pick a random one of those.

Enumeration e = NetworkInterface.getNetworkInterfaces();
while(e.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface)e.nextElement();
Enumeration e2 = ni.getInetAddresses();
while (e2.hasMoreElements()){
InetAddress ip = (InetAddress)e2.nextElement();
// save ip somewhere
}
}

Arne


All times are GMT. The time now is 08:36 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.