Java IP Address Get getExternalIPAddress()

Here you can find the source of getExternalIPAddress()

Description

get External IP Address

License

Open Source License

Declaration

public static String getExternalIPAddress() 

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 getExternalIPAddress() {
        BufferedReader in = null;
        try {/*  w  w  w  .j  av  a 2 s . com*/
            URL whatismyip = new URL("http://automation.whatismyip.com/n09230945.asp");
            in = new BufferedReader(new InputStreamReader(whatismyip.openStream()));
            return in.readLine(); //you get the IP as a String
        } catch (IOException ex) {
        } finally {
            try {
                in.close();
            } catch (IOException ex) {
            }
        }
        return null;
    }
}

Related

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