Here you can find the source of getLocalHostName()
public static String getLocalHostName()
//package com.java2s; /******************************************************************************* * * Copyright (c) 2002, 2008 IBM Corporation, Beacon Information Technology Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w w w . j a v a 2 s .c o m * IBM - Initial API and implementation * BeaconIT - Initial API and implementation *******************************************************************************/ import java.net.InetAddress; public class Main { /** * Get local host name. * @return the local host name. */ public static String getLocalHostName() { String sLocalHostName; try { // Get local host name sLocalHostName = InetAddress.getLocalHost().getHostName(); } catch (Exception e) { // Set default local host name sLocalHostName = "127.0.0.1"; } // Return local host name return sLocalHostName; } }