Here you can find the source of getIp()
public static String getIp() throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { /**/*from w w w . j ava2 s .co m*/ * Checks public IP address from Amazon's API * **/ public static String getIp() throws IOException { URL whatismyip = new URL("http://checkip.amazonaws.com"); BufferedReader in = null; try { in = new BufferedReader(new InputStreamReader(whatismyip.openStream())); String ip = in.readLine(); return ip; } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } }