Here you can find the source of getIp()
public static final String getIp()
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.InetAddress; import java.net.URL; import java.net.UnknownHostException; public class Main { private static String ipAddress = null; /** @return This machine's external ip address(or local, if the external * could// w w w. j a v a2 s . com * not be determined) */ public static final String getIp() { if (ipAddress == null) { try { URL whatismyip = new URL("http://checkip.amazonaws.com"); try (BufferedReader in = new BufferedReader(new InputStreamReader(whatismyip.openStream()))) { ipAddress = in.readLine(); } } catch (Throwable e) { System.err.println("Unable to retrieve this machine's external ip: " + e.getMessage());//PrintUtil.printThrowable(e); try { ipAddress = InetAddress.getLocalHost().toString(); } catch (UnknownHostException e1) { ipAddress = ""; } } } if (ipAddress == null) { ipAddress = ""; } return ipAddress; } }