Java IP Address Get getExternalIp()

Here you can find the source of getExternalIp()

Description

get External Ip

License

Open Source License

Declaration

public static String getExternalIp() 

Method Source Code


//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 getExternalIp() {
        BufferedReader in = null;
        try {// w w  w .j  a  v  a  2  s  .  c o m
            URL whatismyip = new URL("http://checkip.amazonaws.com");
            in = new BufferedReader(new InputStreamReader(whatismyip.openStream()));
            String ip = in.readLine();
            return ip;
        } catch (Exception exc) {
            System.out.println("Exception getting external IP: " + exc.getMessage());
            return "";
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

Related

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