question: 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 ; }
target:  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.