Here you can find the source of GetLocalHostName()
public static final String GetLocalHostName()
//package com.java2s; //License from project: Open Source License import java.net.*; public class Main { public static final String GetLocalHostName() { String localHostName = "Unknown"; try {/*from ww w .j av a 2 s . co m*/ InetAddress lhost = java.net.InetAddress.getLocalHost(); localHostName = lhost.getHostName(); if ("localhost".equals(localHostName)) localHostName = lhost.getHostAddress(); } catch (Exception e) { localHostName = "Unknown"; } return localHostName; } }