Here you can find the source of getPublicIP()
public static String getPublicIP()
//package com.java2s; //License from project: Open Source License import java.io.*; import java.net.*; public class Main { public static String getPublicIP() { String raw = downloadString("http://checkip.dyndns.org/"); raw = raw.substring(raw.indexOf(":") + 1).trim(); raw = raw.substring(0, raw.indexOf("<")).trim(); return raw; }/*from w w w . jav a2 s.c o m*/ public static String downloadString(String url) { String s = null; try { BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(url).openStream())); String ss; while ((ss = reader.readLine()) != null) s += ss; } catch (IOException ex) { ex.printStackTrace(); } return s; } }