MCPcopy
hub / github.com/oshi/oshi / identifyVM

Method identifyVM

oshi-demo/src/main/java/oshi/demo/DetectVM.java:86–119  ·  view source on GitHub ↗

The function attempts to identify which Virtual Machine (VM) based on common VM signatures in MAC address and computer model. @return A string indicating the machine's virtualization info if it can be determined, or an emptry string otherwise.

()

Source from the content-addressed store, hash-verified

84 * determined, or an emptry string otherwise.
85 */
86 public static String identifyVM() {
87 SystemInfo si = new SystemInfo();
88 HardwareAbstractionLayer hw = si.getHardware();
89 // Check CPU Vendor
90 String vendor = hw.getProcessor().getProcessorIdentifier().getVendor().trim();
91 if (vmVendor.containsKey(vendor)) {
92 return vmVendor.get(vendor);
93 }
94
95 // Try well known MAC addresses
96 List<NetworkIF> nifs = hw.getNetworkIFs();
97 for (NetworkIF nif : nifs) {
98 String mac = nif.getMacaddr().toUpperCase();
99 String oui = mac.length() > 7 ? mac.substring(0, 8) : mac;
100 if (vmMacAddressProps.containsKey(oui)) {
101 return vmMacAddressProps.getProperty(oui);
102 }
103 }
104
105 // Try well known models
106 String model = hw.getComputerSystem().getModel();
107 for (String vm : vmModelArray) {
108 if (model.contains(vm)) {
109 return vm;
110 }
111 }
112 String manufacturer = hw.getComputerSystem().getManufacturer();
113 if ("Microsoft Corporation".equals(manufacturer) && "Virtual Machine".equals(model)) {
114 return "Microsoft Hyper-V";
115 }
116
117 // Couldn't find VM, return empty string
118 return "";
119 }
120}

Callers 1

mainMethod · 0.95

Calls 10

getHardwareMethod · 0.95
getProcessorMethod · 0.95
getNetworkIFsMethod · 0.95
getComputerSystemMethod · 0.95
getVendorMethod · 0.65
getMacaddrMethod · 0.65
getModelMethod · 0.65
getManufacturerMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected