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.InputStreamReader;

import java.net.URL;

public class Main {
    public static String getExternalIP() {
        try {/*from w w w  . j a v  a 2  s  . c  om*/
            URL myIp = new URL("http://checkip.dyndns.org/");
            BufferedReader in = new BufferedReader(new InputStreamReader(myIp.openStream()));
            String s = in.readLine();
            return s.substring(s.lastIndexOf(":") + 2, s.lastIndexOf("</body>"));
        } catch (Exception ex) {
            return "error " + ex;
        }
    }
}

Related

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