Here you can find the source of getHostAddress()
public static String getHostAddress() throws Exception
//package com.java2s; //License from project: Apache License import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumeration; public class Main { public static String getHostAddress() throws Exception { final Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { final NetworkInterface current = interfaces.nextElement(); if (!current.isUp() || current.isLoopback() || current.isVirtual()) { continue; }//from www .ja va2s . c o m final Enumeration<InetAddress> addresses = current.getInetAddresses(); while (addresses.hasMoreElements()) { final InetAddress current_addr = addresses.nextElement(); if (current_addr.isLoopbackAddress()) { continue; } if (current_addr instanceof Inet4Address) { return current_addr.getHostAddress(); } } } throw new RuntimeException("Couldn't deduce host address"); } }