Here you can find the source of getLocalIP()
public static String getLocalIP()
//package com.java2s; //License from project: Apache License import java.net.InetAddress; import java.net.UnknownHostException; public class Main { public static String getLocalIP() { try {/*from w w w. j a v a 2 s . c o m*/ InetAddress localHost = InetAddress.getLocalHost(); String hostAddress = localHost.getHostAddress(); return hostAddress; } catch (UnknownHostException e) { throw new RuntimeException(e); } } }