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.InputStreamReader; import java.net.URL; public class Main { public static String getExternalIP() { try {/*from w w w . j a v a 2 s . c om*/ URL myIp = new URL("http://checkip.dyndns.org/"); BufferedReader in = new BufferedReader(new InputStreamReader(myIp.openStream())); String s = in.readLine(); return s.substring(s.lastIndexOf(":") + 2, s.lastIndexOf("</body>")); } catch (Exception ex) { return "error " + ex; } } }