Java Utililty Methods Mac Address Get

List of utility methods to do Mac Address Get

Description

The list of methods to do Mac Address Get are organized into topic(s).

Method

String[]getMacAddresses()
get Mac Addresses
List<String> result = new ArrayList<>();
Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
if (nis != null) {
    while (nis.hasMoreElements()) {
        byte[] mac = nis.nextElement().getHardwareAddress();
        if (mac != null && mac.length == 6) {
            result.add(String.format("%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3],
                    mac[4], mac[5]));
...
StringgetMacAddressString()
get Mac Address String
byte[] macByte = getMacAddress();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < macByte.length; i++) {
    sb.append(String.format("%02X%s", macByte[i], (i < macByte.length - 1) ? ":" : ""));
return sb.toString();
String[]getMacAddrs()
Returns the hardware address (usually MAC) of the interface if it has one and if it can be accessed given the current privileges.
Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
StringBuilder buf = new StringBuilder();
while (e.hasMoreElements()) {
    NetworkInterface network = e.nextElement();
    if (network != null) {
        byte[] nmac = network.getHardwareAddress();
        if (nmac != null) {
            buf.append(hexdump(nmac));
...
StringGetMachineAddress()
Indicates the IP address of the machine where this software is being run
return InetAddress.getLocalHost().getHostAddress();