// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import java.net.NetworkInterface;
import java.net.InetAddress;
import java.util.Enumeration;

public class NI16 {
    public static void main(String[] args) throws Exception {
        Enumeration e = NetworkInterface.getNetworkInterfaces();
        while(e.hasMoreElements()) {
            NetworkInterface ni = (NetworkInterface)e.nextElement();
            System.out.println("Net interface: " + ni.getName());
            Enumeration e2 = ni.getInetAddresses();
            while (e2.hasMoreElements()){
                InetAddress ip = (InetAddress)e2.nextElement();
                System.out.println("IP address: " + ip.getHostAddress());
            }
            byte[] mac = ni.getHardwareAddress();
            if(mac != null) {
                System.out.printf("%02X:%02X:%02X:%02X:%02X:%02X\n",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
            }
        }
    }
}
