Java Host Address Get getHostAddresses()

Here you can find the source of getHostAddresses()

Description

get Host Addresses

License

Apache License

Declaration

@SuppressWarnings("rawtypes")
    public final static List<String> getHostAddresses() throws Throwable 

Method Source Code

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

import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;

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

import java.util.List;

public class Main {
    @SuppressWarnings("rawtypes")
    public final static List<String> getHostAddresses() throws Throwable {

        List<String> result = new ArrayList<>();

        Enumeration e = NetworkInterface.getNetworkInterfaces();
        while (e.hasMoreElements()) {
            NetworkInterface n = (NetworkInterface) e.nextElement();
            Enumeration ee = n.getInetAddresses();
            while (ee.hasMoreElements()) {
                InetAddress i = (InetAddress) ee.nextElement();
                //System.out.println(i.getHostAddress());
                if (i instanceof Inet6Address || i
                        .isLoopbackAddress()/*.getHostAddress().contains("127.0.0.1") || i.getHostAddress().contains("0:0:0:0:0")*/)
                    continue;
                result.add(i.getHostAddress());
            }//from   w  w  w . j a  va  2s .  c  o  m
        }

        return result;
    }
}

Related

  1. getHostAddress(boolean promiscuous)
  2. getHostAddress(final String name)
  3. getHostAddress(String hostname)
  4. getHostAddress(String hostPort)
  5. getHostAddresses()
  6. getHostAddresses()
  7. getHostAddressFromProperty(final String property)
  8. getHostExternalAddr()
  9. getHostName(String addr)