Here you can find the source of getHostname()
public static String getHostname()
//package com.java2s; /*/*from www . j a v a2s . c o m*/ * License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt */ import java.net.InetAddress; import java.net.UnknownHostException; public class Main { public static String getHostname() { String retHost = "UNKNOWN_HOST"; try { String host = InetAddress.getLocalHost().getCanonicalHostName(); if (host != null) { int idx = host.indexOf("."); if (idx > -1) { retHost = host.substring(0, idx); try { int v = Integer.parseInt(retHost); retHost = host; } catch (NumberFormatException e) { // do nothing, we found a host name } } else { retHost = host; } } } catch (UnknownHostException e) { retHost = "UNKNOWN_HOST"; } return retHost; } }