Here you can find the source of getExternalIPAddress()
public static String getExternalIPAddress()
//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; import java.net.URLConnection; public class Main { public static String getExternalIPAddress() { BufferedReader in = null; try {/* www . j av a 2s .c om*/ // URL whatismyip = new URL("http://myip.dnsomatic.com"); // in = new BufferedReader(new InputStreamReader(whatismyip.openStream())); // return in.readLine(); //you get the IP as a String URL whatismyip = new URL("http://checkip.amazonaws.com"); URLConnection connection = whatismyip.openConnection(); connection.addRequestProperty("Protocol", "Http/1.1"); connection.addRequestProperty("Connection", "keep-alive"); connection.addRequestProperty("Keep-Alive", "1000"); connection.addRequestProperty("User-Agent", "Web-Agent"); in = new BufferedReader(new InputStreamReader(whatismyip.openStream())); return in.readLine(); //you get the IP as a String } catch (IOException ex) { } finally { try { in.close(); } catch (IOException ex) { } } return null; } }