Here you can find the source of getHostName()
public static String getHostName()
//package com.java2s; //License from project: Apache License import java.net.InetAddress; public class Main { public static String getHostName() { try {/*from ww w . ja va 2 s. c o m*/ return InetAddress.getLocalHost().getHostName(); } catch (Exception e) { return null; } } }