How do you determine which network interface is connected to the internet using Java? For example, I run
InetAddress.getLocalHost().getHostAddress();
I was having the same problem, and came up with this solution (not as thorough as the answer, but I needed something that didn't try to connect to the internet.
Based on known OUI for mac addresses: http://standards-oui.ieee.org/oui.txt
I made a quick check (could be optimized with binary logic)
private static boolean isVmwareMac(byte[] mac) {
byte invalidMacs[][] = {
{0x00, 0x05, 0x69}, //VMWare
{0x00, 0x1C, 0x14}, //VMWare
{0x00, 0x0C, 0x29}, //VMWare
{0x00, 0x50, 0x56} //VMWare
};
for (byte[] invalid: invalidMacs){
if (invalid[0] == mac[0] && invalid[1] == mac[1] && invalid[2] == mac[2])
return true;
}
return false;
}