NetworkInterface: getHardwareAddress() throws SocketException : NetworkInterface « java.net « Java by API






NetworkInterface: getHardwareAddress() throws SocketException

  

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

public class Main {
  public static void main(String[] args) throws Exception {
    InetAddress address = InetAddress.getLocalHost();

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

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

   
    
  








Related examples in the same category

1.NetworkInterface: getByInetAddress(InetAddress addr)
2.NetworkInterface: getDisplayName()
3.NetworkInterface: getHardwareAddress()
4.NetworkInterface: getInetAddresses()
5.NetworkInterface: getInterfaceAddresses()
6.NetworkInterface: getMTU()
7.NetworkInterface: getName()
8.NetworkInterface: isLoopback()
9.NetworkInterface: isPointToPoint()
10.NetworkInterface: isUp()
11.NetworkInterface: isVirtual()
12.NetworkInterface: supportsMulticast()