/** * Figure out some random hostname for this computer * * @return * @throws SocketException */ public static String getHostname() throws SocketException { try { String hostname = java.net.InetAddress.getLocalHost().getHostName(); if (hostname != null) return hostname; } catch (UnknownHostException e) { } Set<InetAddress> addrs = EndpointUtil.getInetAddresses(); for (InetAddress addr : addrs) { String hostaddr = addr.getHostAddress(); String hostname = EndpointUtil.inetAddressToName(addr); if (!hostaddr.equals(hostname)) return hostname; } return "localhost"; }