Here you can find the source of getPublicIP2()
public static String getPublicIP2() throws Exception
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static String getPublicIP2() throws Exception { String inputLine = ""; String read = ""; String ip = ""; URL url = new URL("http://checkip.dyndns.org/"); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); while ((read = in.readLine()) != null) { inputLine += read;/*from ww w. ja va 2 s.c o m*/ } // //System.out.println(inputLine); String[] strs = inputLine.split(":"); ip = strs[1].split("<")[0]; return ip.trim(); } }