Java: Obtenir l’adresse Mac d’un Ordinateur

Author:

 adresse, java
{filelink=9121}


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

public class MacAdresse
 {
  public static void main(String[] args) throws Exception
  	{

  	// Obtenir l'adresse IP de la machine locale
    InetAddress address = InetAddress.getLocalHost();

    NetworkInterface ni = NetworkInterface.getByInetAddress(address);
    byte[] mac = ni.getHardwareAddress();

   // Afficher l'adresse Mac
    for (int i = 0; i < mac.length; i++) {
      System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "");
    }
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *