Jevivre xavie Jevivre xavie - 3 years ago 145
Java Question

Get MAC address on local machine with Java

I can use

ip = InetAddress.getLocalHost();
NetworkInterface.getByInetAddress(ip);


to obtain the mac address, but if I use this code in an offline machine it doesn't work.

So, How can I get the Mac address?

Answer Source

With Java 6+, you can use NetworkInterface.getHardwareAddress.

Bear in mind that a computer can have no network cards, especially if it's embedded or virtual. It can also have more than one. You can get a list of all network cards with NetworkInterface.getNetworkInterfaces().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download