Thanks to all for the interesting answers and references that I will
definitely study and keep for future reference. I ended up using Ivo's
simple (I love the KISS principle) and it works in my environment:
java.net.InetAddress.getLocalHost().getHostAddress()
I added that line in the layout file main.gsp:
<div class="appaddress">Tip: To access the application from another
computer on the same local network, use this address in a web browser:
${request.getScheme()}://${java.net.InetAddress.getLocalHost().getHostAddress()
+ ((request.getLocalPort() != 80) ? ':' + request.getLocalPort() : '') +
request.getContextPath()}</div>
I wrote that application for a small business (just a few people in an
office), the Tomcat server with the Grails application are hosted on one of
the staff's computer, not networked at the moment but will be in the near
future. As they use another company to maintain their computers and to
install the network, I wanted to provide them with a very simple help to
find the application on the network even if the server changes IP address.
So the message above shows the application URL to use, even from the same
computer where the app lives. The users just have to copy that address in
the browser of the other computers when the LAN is in place.
Thanks again all for your help.
Fred
Post by houbiePost by Fred JanonI would like to find out the IP address (the real one not 127.0.0.1 or
localhost) ...
The simple answer: InetAddress.getLocalHost().getHostAddress().
The reality: your host can have multiple network interfaces (wired, wireless
...) and hence multiple IP addresses. So getLocalHost() will select (almost)
ramdom one of them if you don't specify the interface explicitly.
Grtz,
Ivo
--
http://www.nabble.com/How-to-get-the-IP-address-of-the-machine-where-the-code-is-running--tp20600752p20601442.html
Sent from the grails - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email