1 16 17 package org.apache.axis.utils; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.axis.components.logger.LogFactory; 21 22 import java.net.InetAddress ; 23 import java.net.UnknownHostException ; 24 25 29 30 public class NetworkUtils { 31 36 public static final String LOCALHOST = "127.0.0.1"; 37 38 41 private NetworkUtils() { 42 } 43 44 protected static Log log = 45 LogFactory.getLog(NetworkUtils.class.getName()); 46 47 56 public static String getLocalHostname() { 57 InetAddress address; 58 String hostname; 59 try { 60 address = InetAddress.getLocalHost(); 61 hostname = address.getHostName(); 63 if (hostname == null || hostname.length() == 0) { 64 hostname = address.toString(); 65 } 66 } catch (UnknownHostException noIpAddrException) { 67 68 if(log.isDebugEnabled()) { 71 log.debug("Failed to lookup local IP address",noIpAddrException); 72 } 73 hostname = LOCALHOST; 74 } 75 return hostname; 76 } 77 } 78 | Popular Tags |