Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Get IP tomcat server

Reply
Thread Tools

Get IP tomcat server

 
 
Sylvain
Guest
Posts: n/a
 
      03-12-2008
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


 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      03-13-2008
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


 
Reply With Quote
 
 
 
 
Sylvain
Guest
Posts: n/a
 
      03-13-2008
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" <> a écrit dans le message de news:
47d895c2$0$90262$...
> 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
>
>



 
Reply With Quote
 
Sylvain
Guest
Posts: n/a
 
      03-13-2008
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" <> a écrit dans le message de news:
47d8e476$0$894$...
> 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" <> a écrit dans le message de news:
> 47d895c2$0$90262$...
>> 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
>>
>>

>
>



 
Reply With Quote
 
Nigel Wade
Guest
Posts: n/a
 
      03-13-2008
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 :
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      03-14-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tomcat error-Could not load Tomcat server configuration sjoshi Java 0 09-27-2005 06:47 PM
Tomcat 4.1.31 - huge count of webapps, Tomcat hangs up Martin Eberle Java 2 12-03-2004 07:10 PM
Tomcat Web application manager - Virtual host Tomcat 4.30 + Apache2 + JK2 connector with multi IPs Joe Java 0 07-12-2004 03:06 PM
Apache Tomcat 4.1.24: problem with Tomcat Administration link Christos Gravvanis Java 0 07-07-2004 05:21 PM
[TOMCAT] Tomcat crashes %=zerointeractive.it% Java 1 01-22-2004 12:08 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57