!7 p { // Set up constants new SS vmMap; vmMap.put("00:50:56", "VMware ESX 3"); vmMap.put("00:0C:29", "VMware ESX 3"); vmMap.put("00:05:69", "VMware ESX 3"); vmMap.put("00:03:FF", "Microsoft Hyper-V"); vmMap.put("00:1C:42", "Parallels Desktop"); vmMap.put("00:0F:4B", "Virtual Iron 4"); vmMap.put("00:16:3E", "Xen or Oracle VM"); vmMap.put("08:00:27", "Sun xVM VirtualBox"); String[] vmArray = { "Linux KVM", "Linux lguest", "OpenVZ", "Qemu", "Microsoft Virtual PC", "VMWare", "linux-vserver", "Xen", "FreeBSD Jail", "OpenVZ Host", "VirtualBox", "Parallels", "Linux Containers", "LXC" }; HardwareAbstractionLayer hw = oshi_hardware(); // Try well known MAC addresses NetworkIF[] nifs = hw.getNetworkIFs(); boolean isvm = false; for (NetworkIF nif : nifs) { String mac = nif.getMacaddr().substring(0, 8).toUpperCase(); if (vmMap.containsKey(mac)) { print("On a VM: " + vmMap.get(mac)); isvm = true; break; } } // Try well known models if (!isvm) { String model = hw.getComputerSystem().getModel(); print(model); for (String vm : vmArray) { if (model.contains(vm)) { print("On a VM: " + vm); isvm = true; break; } } } if (!isvm) { print("Couldn't detect VM"); } }