Here you can find the source of getLocalHostName()
public static String getLocalHostName()
//package com.java2s; //License from project: Open Source License public class Main { /**/* w ww.j a v a 2 s. c o m*/ * Gets the host name for the local machine. * * @return A string with the local hostname or null on error. */ public static String getLocalHostName() { java.net.InetAddress addr = null; try { addr = java.net.InetAddress.getLocalHost(); } catch (Exception ignore) { return (null); } return (addr.getHostName()); } }