Listing 2 myMacAddress method
public byte[] myMacAddress(int networkInterfaceID) { /* Verify that we obtained a valid networkInterfaceID */ if (networkInterfaceID < 0 || devices.length <= networkInterfaceID) return null; /* Set device to the network interface specified by the networkInterfaceID */ NetworkInterface device = devices[networkInterfaceID]; /* Get the MAC address of the device */ byte[] returnByte = device.mac_address; /* Convert the MAC address to a string so we can verify we have a valid MAC address */ String macString = ""; for (byte b : returnByte) macString += Integer.toHexString(b&0xff) + ":"; /* This function is to fix a problem with the windows jpcap and obtaining a bad MAC address */ if (macString.equalsIgnoreCase("0:0:0:0:0:0:")) returnByte = myMacAddress(0); /* return the mac address */ return returnByte; }