Tried to use the getHardwareAddress() method to get the mac address of my network card, however according to NetworkInterface.getNetworkInterfaces() I have over 20 network interfaces. Ive narrowed it down to one by checking other attributes, but is this going to work in all (or at least most cirumstances) and operating systems, only tried on a WIndows 7 PC.
And if a computer has two network cards, can I find out which one is actually being used for a current internet connection ?
Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
while(e.hasMoreElements())
{
NetworkInterface ni = e.nextElement();
if(ni!=null && ni.getHardwareAddress()!=null &&ni.getInetAddresses().hasMoreElements() && ni.supportsMulticast())
{
String macAddress = Hex.encodeHexString(ni.getHardwareAddress());
System.out.println("MACADDRESSIS"+macAddress);
}
}