Here you can find the source of getExternalIp()
public static String getExternalIp()
//package com.java2s; // it under the terms of the GNU Lesser General Public License as published by import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; public class Main { /**// w w w.j a va 2s .co m * Fetches the external ip through amazonaw's utility. Note that this method may break at any given point, do not use * for essential functionality * @return Your external ip */ public static String getExternalIp() { try { URL url = new URL("http://checkip.amazonaws.com/"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); return in.readLine(); } catch (MalformedURLException e) { // This will deterministically never happen return null; } catch (IOException e) { return null; } } }