Java Host Name Get getAllMyHostAdresses()

Here you can find the source of getAllMyHostAdresses()

Description

get All My Host Adresses

License

Open Source License

Declaration

public static Set<InetAddress> getAllMyHostAdresses() throws Exception 

Method Source Code

//package com.java2s;
/*//  w  w  w. java2 s.  c  o m
 * (C) Copyright IBM Corp. 2008
 *
 * LICENSE: Eclipse Public License v1.0
 * http://www.eclipse.org/legal/epl-v10.html
 */

import java.net.InetAddress;

import java.net.NetworkInterface;

import java.util.Enumeration;
import java.util.HashSet;

import java.util.Set;

public class Main {
    public static Set<InetAddress> getAllMyHostAdresses() throws Exception {
        Set<InetAddress> addresses = new HashSet<InetAddress>();

        Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
        while (en.hasMoreElements()) {
            Enumeration<InetAddress> ias = en.nextElement().getInetAddresses();
            while (ias.hasMoreElements())
                addresses.add(ias.nextElement());
        }

        return addresses;
    }
}

Related

  1. getByName(String host)
  2. getCanonicalHostName()
  3. getCanonicalHostname()
  4. getCanonicalHostName()