Enumeration of NetworkInterface : NetworkInterface « Network « Java Tutorial






import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;
import java.util.Enumeration;

public class NetParms {
  public static void main(String[] args) throws SocketException {
    Enumeration<NetworkInterface> eni;
    eni = NetworkInterface.getNetworkInterfaces();
    for (NetworkInterface ni : Collections.list(eni)) {
      System.out.println("Name = " + ni.getName());
      System.out.println("Display Name = " + ni.getDisplayName());
      System.out.println("Loopback = " + ni.isLoopback());
      System.out.println("Up and running = " + ni.isUp());
      System.out.println("MTU = " + ni.getMTU());
      System.out.println("Supports multicast = " + ni.supportsMulticast());
      System.out.println("Sub-interfaces");
      Enumeration<NetworkInterface> eni2;
      eni2 = ni.getSubInterfaces();
      for (NetworkInterface ni2 : Collections.list(eni2))
        System.out.println("   " + ni2);
      System.out.println();
    }
  }
}








19.8.NetworkInterface
19.8.1.Interface Lister
19.8.2.Programmatic Access to Network Parameters
19.8.3.An updated version of the ListNets program that uses the NetworkInterface enhancements
19.8.4.Get MAC address of a host: java.net.NetworkInterface.getHardwareAddress().
19.8.5.Report By Name
19.8.6.Enumeration of NetworkInterface
19.8.7.Report By Address
19.8.8.NetworkInterface