Here you can find the source of getHostName()
public static String getHostName()
//package com.java2s; /**/*from w w w.j a v a2s . co m*/ * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. * * If it is not possible or desirable to put the notice in a particular file, * then You may include the notice in a location (such as a LICENSE file in a * relevant directory) where a recipient would be likely to look for such a * notice. * * */ import java.net.InetAddress; public class Main { private static String myHostname = null; /** * returns the lowercase hostname * * @return */ public static String getHostName() { if (myHostname == null) { try { InetAddress addr = InetAddress.getLocalHost(); // Get IP Address // byte[] ipAddr = addr.getAddress(); // Get hostname myHostname = addr.getHostName().toLowerCase(); } catch (Exception e) { myHostname = "ADDRESS_UNKNOWN"; } } return myHostname; } }