Get IP tomcat server

Discussion in 'Java' started by Sylvain, Mar 12, 2008.

  1. Sylvain

    Sylvain Guest

    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
     
    Sylvain, Mar 12, 2008
    #1
    1. Advertising

  2. Sylvain

    Arne Vajhøj Guest

    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
     
    Arne Vajhøj, Mar 13, 2008
    #2
    1. Advertising

  3. Sylvain

    Sylvain Guest

    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
    >
    >
     
    Sylvain, Mar 13, 2008
    #3
  4. Sylvain

    Sylvain Guest

    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
    >>
    >>

    >
    >
     
    Sylvain, Mar 13, 2008
    #4
  5. Sylvain

    Nigel Wade Guest

    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
     
    Nigel Wade, Mar 13, 2008
    #5
  6. Sylvain

    Arne Vajhøj Guest

    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
     
    Arne Vajhøj, Mar 14, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. %=zerointeractive.it%

    [TOMCAT] Tomcat crashes

    %=zerointeractive.it%, Jan 22, 2004, in forum: Java
    Replies:
    1
    Views:
    442
    Erwin Moller
    Jan 22, 2004
  2. Christos Gravvanis
    Replies:
    0
    Views:
    2,086
    Christos Gravvanis
    Jul 7, 2004
  3. Joe
    Replies:
    0
    Views:
    1,731
  4. Martin Eberle
    Replies:
    2
    Views:
    864
  5. sjoshi
    Replies:
    0
    Views:
    6,689
    sjoshi
    Sep 27, 2005
Loading...

Share This Page