Java IP Address Get getIPs()

Here you can find the source of getIPs()

Description

get I Ps

License

Open Source License

Declaration

public final static String getIPs() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.Inet4Address;
import java.net.InetAddress;

import java.net.NetworkInterface;

import java.util.Enumeration;

public class Main {

    public final static String getIPs() {
        StringBuilder v_Ret = new StringBuilder();
        Enumeration<?> v_NetInterfaces = null;
        InetAddress v_IP = null;//from w  ww  . ja va  2s.com
        try {
            v_NetInterfaces = NetworkInterface.getNetworkInterfaces();
        } catch (java.net.SocketException e) {
            return v_Ret.toString();
        }

        while (v_NetInterfaces.hasMoreElements()) {
            NetworkInterface v_NetInterface = (NetworkInterface) v_NetInterfaces.nextElement();
            Enumeration<?> v_Addresses = v_NetInterface.getInetAddresses();
            int v_Count = 0;

            v_Ret.append(v_NetInterface.getName()).append("=");

            while (v_Addresses.hasMoreElements()) {
                v_IP = (InetAddress) v_Addresses.nextElement();
                if (v_IP != null && v_IP instanceof Inet4Address) {
                    v_Ret.append(v_IP.getHostAddress());
                    v_Count++;

                    if (v_Count > 1) {
                        v_Ret.append(";");
                    }
                }
            }

            v_Ret.append(" ");
        }

        return v_Ret.toString().trim();
    }
}

Related

  1. getIPFromInterface(String ni)
  2. getIPFromNetworkInterface()
  3. getIpHostnameLocal()
  4. getIPList(String address)
  5. getIPList(String s, String s1)
  6. getIPs()
  7. getIPv4Address()
  8. getIPV4Address(List addresses)
  9. getIPv4Address(NetworkInterface iface)