Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

Get IP tomcat server

Thread view: 
Sylvain - 12 Mar 2008 15:38 GMT
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 - 13 Mar 2008 03:47 GMT
> 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 - 13 Mar 2008 09:23 GMT
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

>> 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 - 13 Mar 2008 11:42 GMT
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

> Hi !
>
[quoted text clipped - 12 lines]
>>
>> Arne
Nigel Wade - 13 Mar 2008 13:17 GMT
> 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.

Signature

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 - 14 Mar 2008 01:52 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.