Java Utililty Methods IP Address Get

List of utility methods to do IP Address Get

Description

The list of methods to do IP Address Get are organized into topic(s).

Method

StringgetStrLocalIP()
get Str Local IP
String ip = null;
Enumeration<NetworkInterface> enuNI = NetworkInterface.getNetworkInterfaces();
begin: while (enuNI.hasMoreElements()) {
    NetworkInterface ni = (NetworkInterface) enuNI.nextElement();
    Enumeration<InetAddress> enuAddress = ni.getInetAddresses();
    while (enuAddress.hasMoreElements()) {
        InetAddress address = enuAddress.nextElement();
        if (!address.isSiteLocalAddress() && !address.isLoopbackAddress()
...
StringgetVisibleIp()
get Visible Ip
String ip = getProperty("ip");
if (ip == null || ip.trim().length() == 0) {
    InputStream in = null;
    try {
        HttpURLConnection connection = (HttpURLConnection) new URL("https://cp.vu/show_my_ip")
                .openConnection();
        ip = new BufferedReader(new InputStreamReader(in = connection.getInputStream())).readLine();
    } catch (IOException e) {
...
StringgetWinLocalIP()
get Win Local IP
String ip = "";
try {
    Enumeration<?> e1 = (Enumeration<?>) NetworkInterface.getNetworkInterfaces();
    while (e1.hasMoreElements()) {
        NetworkInterface ni = (NetworkInterface) e1.nextElement();
        Enumeration<?> e2 = ni.getInetAddresses();
        while (e2.hasMoreElements()) {
            InetAddress ia = (InetAddress) e2.nextElement();
...
InetAddressgetWinLocalIp()
get Win Local Ip
InetAddress inet = InetAddress.getLocalHost();
return inet;