Java InetAddress Create getLocalInetAddresses()

Here you can find the source of getLocalInetAddresses()

Description

get Local Inet Addresses

License

Open Source License

Declaration

public static List<InetAddress> getLocalInetAddresses() throws SocketException 

Method Source Code


//package com.java2s;
/*/*from  w  w w  . j  a v a 2s  .c o  m*/
 * Copyright (c) 2011 - 2012. Elega9t Ltd. All rights reserved.
 * ELEGA9T PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.Copyright (c) 2011 - 2012. Elega9t Ltd. All rights reserved.
 */

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import static java.net.NetworkInterface.getNetworkInterfaces;

public class Main {
    public static List<InetAddress> getLocalInetAddresses() throws SocketException {
        List<InetAddress> addrList = new ArrayList<InetAddress>();
        Enumeration<NetworkInterface> networkInterfaces = getNetworkInterfaces();
        while (networkInterfaces.hasMoreElements()) {
            NetworkInterface ifc = networkInterfaces.nextElement();
            if (ifc.isUp()) {
                Enumeration<InetAddress> inetAddresses = ifc.getInetAddresses();
                while (inetAddresses.hasMoreElements()) {
                    InetAddress addr = inetAddresses.nextElement();
                    addrList.add(addr);
                }
            }
        }
        return addrList;
    }
}

Related

  1. getLocalInetAddress()
  2. getLocalInetAddress()
  3. getLocalInetAddress(String host)
  4. getLocalInetAddress(String host)
  5. getLocalInetAddresses()
  6. getLocalInetAddresses(boolean includeLoopback)
  7. getMacAddress(InetAddress addr)
  8. getMacAddress(InetAddress address)
  9. getMieleUUIDLowerPart(int deviceType50523, InetAddress address)