public static java.lang.String | getLocalHostname()Get the string defining the hostname of the system, as taken from
the default network adapter of the system. There is no guarantee that
this will be fully qualified, or that it is the hostname used by external
machines to access the server.
If we cannot determine the name, then we return the default hostname,
which is defined by {@link #LOCALHOST}
InetAddress address;
String hostname;
try {
address = InetAddress.getLocalHost();
//force a best effort reverse DNS lookup
hostname = address.getHostName();
if (hostname == null || hostname.length() == 0) {
hostname = address.toString();
}
} catch (UnknownHostException noIpAddrException) {
//this machine is not on a LAN, or DNS is unhappy
//return the default hostname
if(log.isDebugEnabled()) {
log.debug("Failed to lookup local IP address",noIpAddrException);
}
hostname = LOCALHOST;
}
return hostname;
|