Here you can find the source of getHostname()
public static final String getHostname()
//package com.java2s; //License from project: Apache License import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.Enumeration; public class Main { /**/*from www . java 2 s .c o m*/ * Determine the hostname of the machine Kettle is running on * * @return The hostname */ public static final String getHostname() { String lastHostname = "localhost"; try { Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); while (en.hasMoreElements()) { NetworkInterface nwi = en.nextElement(); Enumeration<InetAddress> ip = nwi.getInetAddresses(); while (ip.hasMoreElements()) { InetAddress in = (InetAddress) ip.nextElement(); lastHostname = in.getHostName(); // System.out.println(" ip address bound : "+in.getHostAddress()); // System.out.println(" hostname : "+in.getHostName()); // System.out.println(" Cann.hostname : "+in.getCanonicalHostName()); // System.out.println(" ip string : "+in.toString()); if (!lastHostname.equalsIgnoreCase("localhost") && !(lastHostname.indexOf(':') >= 0)) { return lastHostname; } } } } catch (SocketException e) { } return lastHostname; } }