Extract network card address with java.net.NetworkInterface : NetworkInterface « Network Protocol « Java






Extract network card address with java.net.NetworkInterface

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

public class Main {
  public static void main(String args[]) throws SocketException {
    Enumeration<NetworkInterface> nets = NetworkInterface
        .getNetworkInterfaces();

    while (nets.hasMoreElements()) {
      NetworkInterface netint = nets.nextElement();
      System.out.println("Display name: " + netint.getDisplayName());
      System.out.println("Hardware address: "
          + Arrays.toString(netint.getHardwareAddress()));
    }
  }
} 

   
    
  








Related examples in the same category

1.Programmatic Access to Network Parameters
2.An updated version of the ListNets program that uses the NetworkInterface enhancements
3.Get MAC address of a host: java.net.NetworkInterface.getHardwareAddress().
4.Report By Name
5.List Network Interfaces
6.Class for determining a host's IP address.