Here you can find the source of getIpAddress()
public static String getIpAddress()
//package com.java2s; //License from project: Open Source License import java.net.InetAddress; import java.net.URL; public class Main { public static String getIpAddress() { try {/*from ww w . j a v a 2 s . co m*/ return InetAddress.getLocalHost().getHostAddress(); } catch (Exception ex) { } return null; } public static String getIpAddress(String url) { if (url == null || url.isEmpty()) { throw new IllegalArgumentException("URL cannot be null or empty!"); } try { return InetAddress.getByName(new URL(url).getHost()).getHostAddress(); } catch (Exception ex) { throw new IllegalStateException("Cannot get IP address of " + url + "!\n"); } } }