Java IP Address Get getAllLocalIP()

Here you can find the source of getAllLocalIP()

Description

get All Local IP

License

Apache License

Declaration

public static List<String> getAllLocalIP() throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.*;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

public class Main {

    public static List<String> getAllLocalIP() throws Exception {
        List<String> result = new ArrayList<String>();
        Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
        while (netInterfaces.hasMoreElements()) {
            NetworkInterface ni = netInterfaces.nextElement();
            Enumeration<InetAddress> ias = ni.getInetAddresses();
            while (ias.hasMoreElements()) {
                InetAddress ip = ias.nextElement();
                if (!ip.isLoopbackAddress() && (ip instanceof Inet4Address)) {
                    result.add(ip.getHostAddress());
                }/*from   w  w w  .  ja  v a2s  .  c o  m*/
            }
        }
        return result;
    }
}

Related

  1. getAllInternalHostIPs(String hostName)
  2. getAllIp()
  3. getAllIPAddresses()
  4. getAllIPsAndAssignedBroadcastAddresses()
  5. getALLLocalHostIP()
  6. getAllLocalIP()
  7. getAllLocalIPs()
  8. getAllLocalIpv4Addresses()
  9. getAllMyHostIPV4Adresses()