Since JDK 1.6, Java developers are able to access network card detail via NetworkInterface class. In this example, we show you how to get the localhost MAC address in Java.

Example : Get MAC Address via NetworkInterface.getByInetAddress()

Output

Note
This NetworkInterface.getHardwareAddress() method is only allow to access localhost MAC address, not remote host MAC address.

Old day…

Before JDK1.6 is released, many are using command and pattern to get the MAC address in Windows, minor code changes will enable it to get the MAC address in *nux as well.

Example : Get MAC Address via command & pattern

Output

This obsolete method is not really efficient, because it does not display which MAC address is using now, what it did is just print out all the available MAC address currently attached. However, it’s nice to share here.