Here you can find the source of getIpAddressExternal()
public static String getIpAddressExternal()
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; public class Main { public static String getIpAddressExternal() { URL myIP;//from w w w . j a v a 2 s. co m try { myIP = new URL("http://api.externalip.net/ip/"); BufferedReader in = new BufferedReader(new InputStreamReader(myIP.openStream())); return in.readLine(); } catch (Exception e) { try { myIP = new URL("http://myip.dnsomatic.com/"); BufferedReader in = new BufferedReader(new InputStreamReader(myIP.openStream())); return in.readLine(); } catch (Exception e1) { try { myIP = new URL("http://icanhazip.com/"); BufferedReader in = new BufferedReader(new InputStreamReader(myIP.openStream())); return in.readLine(); } catch (Exception e2) { e2.printStackTrace(); } } } return null; } }