public static synchronized Collection<String> allLocalMACs(){
  List<String> macs=new ArrayList<>(3);
  try {
    Enumeration<NetworkInterface> itfs=NetworkInterface.getNetworkInterfaces();
    if (itfs != null) {
      for (      NetworkInterface itf : asIterable(itfs)) {
        byte[] hwAddr=itf.getHardwareAddress();
        if (hwAddr != null && hwAddr.length > 0) {
          String mac=byteArray2HexString(hwAddr);
          if (!macs.contains(mac))           macs.add(mac);
        }
      }
    }
  }
 catch (  SocketException ignore) {
    return Collections.emptyList();
  }
  Collections.sort(macs);
  return macs;
}

public static synchronized Collection < String > allLocalMACs ( ) { List < String > macs = new ArrayList < > ( 3 ) ; try { Enumeration < NetworkInterface > itfs = NetworkInterface . getNetworkInterfaces ( ) ; if ( itfs != null ) { for ( NetworkInterface itf : asIterable ( itfs ) ) { byte [ ] hwAddr = itf . getHardwareAddress ( ) ; if ( hwAddr != null && hwAddr . length > 0 ) { String mac = byteArray2HexString ( hwAddr ) ; if ( ! macs . contains ( mac ) ) macs . add ( mac ) ; } } } } catch ( SocketException ignore ) { return Collections . emptyList ( ) ; } Collections . sort ( macs ) ; return macs ; }
gets a list of all local enabled macs known to this jvm . it is using hardware address of the network interface that is not guaranteed to be mac addresses ( but in most cases it is ) . < p > note that if network interface is disabled - its mac won ' t be included . all local network interfaces are probed including loopbacks . virtual interfaces ( sub - interfaces ) are skipped . < p > note that on linux gethardwareaddress ( ) can return null from time to time if networkinterface . gethardwareaddress ( ) method is called from many threads .
