Here you can find the source of getHostAddress()
public static String getHostAddress() throws UnknownHostException
//package com.java2s; //License from project: Apache License import java.net.InetAddress; import java.net.UnknownHostException; public class Main { public static String getHostAddress() throws UnknownHostException { try {// w w w . j a v a 2 s. c om return (InetAddress.getLocalHost()).getHostAddress(); } catch (UnknownHostException uhe) { String host = uhe.getMessage(); if (host != null) { int colon = host.indexOf(':'); if (colon > 0) { return host.substring(0, colon); } } throw uhe; } } }