[jboss-user] [JNDI/Naming/Network] - Can't get the right IP address when running inside JBoss

anna_karina do-not-reply at jboss.com
Thu Jun 14 09:35:15 EDT 2007


Hi, 

I have the following code in a utility library and can return the right IP address just fine (e.g. 192.168.10.10), when it is called from an independent Java program, or when it is called from some program running on Tomcat:

  | InetAddress addr;
  | try {
  |     addr = InetAddress.getLocalHost();
  | } catch (UnknownHostException e) {
  |     e.printStackTrace();
  |     return null;
  | }
  | byte[] ipAddr = addr.getAddress();
  | String ipAddrStr = "";
  | for (int idx = 0; idx< ipAddr.length; idx++) 
  | {
  |     if (idx > 0) {
  |         ipAddrStr += ".";
  |     }
  |     ipAddrStr += ipAddr[idx]&0xFF;
  | }
  | 
But when the same piece of code is invoked inside JBoss (from a Struts 2 action), this only returns "127.0.0.1".

Could someone tell what's going on, and how could I get the right IP address?

Thanks

ak


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4054363#4054363

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4054363



More information about the jboss-user mailing list