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?
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?
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()
.As for the computer being offline, it usually doesn't have an IP assigned, because DHCP is widely used...
And for the question in the title:
NetworkInterface.getHardwareAddress()