Java IP Address Get getExternalIp()

Here you can find the source of getExternalIp()

Description

Fetches the external ip through amazonaw's utility.

License

Open Source License

Return

Your external ip

Declaration

public static String getExternalIp() 

Method Source Code

//package com.java2s;
// it under the terms of the GNU Lesser General Public License as published by

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    /**//  w  w  w.j a  va 2s .co m
     * Fetches the external ip through amazonaw's utility. Note that this method may break at any given point, do not use
     * for essential functionality
     * @return Your external ip
     */
    public static String getExternalIp() {
        try {
            URL url = new URL("http://checkip.amazonaws.com/");
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            return in.readLine();
        } catch (MalformedURLException e) {
            // This will deterministically never happen
            return null;
        } catch (IOException e) {
            return null;
        }
    }
}

Related

  1. getAllMyHostIPV4Adresses()
  2. getAllUsableIPAddresses()
  3. getExternalIP()
  4. getExternalIp()
  5. getExternalIp()
  6. getExternalIP(String host, String regexPattern)
  7. getExternalIPAddress()
  8. getExternalIPAddress()
  9. getExternalIPAddress()