Here you can find the source of getExternalIp()
public static String getExternalIp()
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; public class Main { public static String getExternalIp() { BufferedReader in = null; try {// w w w .j a v a 2 s . c o m URL whatismyip = new URL("http://checkip.amazonaws.com"); in = new BufferedReader(new InputStreamReader(whatismyip.openStream())); String ip = in.readLine(); return ip; } catch (Exception exc) { System.out.println("Exception getting external IP: " + exc.getMessage()); return ""; } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } }