Java IP Address Get getExternalIPAddress()

Here you can find the source of getExternalIPAddress()

Description

Returns external IP address by sending HTTP request to http://whatismyip.com/automation/n09230945.asp

License

Open Source License

Return

external IP address

Declaration

public static String getExternalIPAddress() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.net.HttpURLConnection;

public class Main {
    /**/*from   w  ww . j a v a  2s.c om*/
     * Returns external IP address by sending HTTP request to http://whatismyip.com/automation/n09230945.asp
     * @return external IP address
     */
    public static String getExternalIPAddress() {
        String url = null;
        try {
            java.net.URL URL = new java.net.URL("http://whatismyip.com/automation/n09230945.asp");
            java.net.HttpURLConnection conn = (HttpURLConnection) URL.openConnection();
            conn.setConnectTimeout(60000);
            conn.setReadTimeout(60000);
            java.io.InputStream InStream = conn.getInputStream();
            java.io.InputStreamReader Isr = new java.io.InputStreamReader(InStream);
            java.io.BufferedReader br = new java.io.BufferedReader(Isr);
            url = br.readLine();
        } catch (Exception e) {
            //
        }
        return url;
    }
}

Related

  1. getExternalIP()
  2. getExternalIp()
  3. getExternalIp()
  4. getExternalIp()
  5. getExternalIP(String host, String regexPattern)
  6. getExternalIPAddress()
  7. getExternalIPAddress()
  8. getFirstLocalNonLoopbackIpAddress()
  9. getFirstNonLoopbackAddress(boolean preferIpv4, boolean preferIPv6)