Here you can find the source of getPublicIP()
public static String getPublicIP()
//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 getPublicIP() { try {/*from w w w .jav a 2 s. c om*/ URL awsCheckIpUrl = new URL("http://checkip.amazonaws.com"); BufferedReader br = new BufferedReader(new InputStreamReader(awsCheckIpUrl.openStream())); return br.readLine(); } catch (IOException e) { e.printStackTrace(); return null; } } }