Java IP Address Get getIpAddressExternal()

Here you can find the source of getIpAddressExternal()

Description

get Ip Address External

License

Apache License

Declaration

public static String getIpAddressExternal() 

Method Source Code


//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;
    }
}

Related

  1. getIpAddresses()
  2. getIPAddresses()
  3. getIPAddresses()
  4. getIpAddresses()
  5. getIpAddressesFromNic()
  6. getIPAddressFromBytes(byte[] bytes)
  7. getIPAddressFromNetworkInterface(String ifaceName)
  8. getIPAddressFromNetworkInterfaces()
  9. getIPAdresses()