Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

37
LINES

< > BotCompany Repo | #1019745 // oshi_detectVM - are we on a virtual machine?

JavaX fragment (include)

1  
scope oshi_detectVM.
2  
3  
static SS #vmMap = litmap(
4  
  "00:50:56", "VMware ESX 3",
5  
  "00:0C:29", "VMware ESX 3",
6  
  "00:05:69", "VMware ESX 3",
7  
  "00:03:FF", "Microsoft Hyper-V",
8  
  "00:1C:42", "Parallels Desktop",
9  
  "00:0F:4B", "Virtual Iron 4",
10  
  "00:16:3E", "Xen or Oracle VM",
11  
  "08:00:27", "Sun xVM VirtualBox");
12  
13  
static S[] #vmArray = { "Linux KVM", "Linux lguest", "OpenVZ", "Qemu", "Microsoft Virtual PC",
14  
    "VMWare", "linux-vserver", "Xen", "FreeBSD Jail", "OpenVZ Host", "VirtualBox", "Parallels",
15  
    "Linux Containers", "LXC" };
16  
17  
static Pair<Bool, S> oshi_detectVM() {
18  
  HardwareAbstractionLayer hw = oshi_hardware();
19  
20  
  // Try well known MAC addresses
21  
  NetworkIF[] nifs = hw.getNetworkIFs();
22  
  for (NetworkIF nif : nifs) {
23  
    S mac = nif.getMacaddr().substring(0, 8).toUpperCase();
24  
    if (vmMap.containsKey(mac))
25  
      ret pair(true, vmMap.get(mac));
26  
  }
27  
28  
  // Try well known models
29  
  S model = hw.getComputerSystem().getModel();
30  
  for (String vm : vmArray)
31  
    if (model.contains(vm))
32  
      ret pair(true, vm);
33  
34  
  ret pair(false, "Could not detect a VM");
35  
}
36  
37  
end scope

download  show line numbers  debug dex  old transpilations   

Travelled to 11 computer(s): bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019745
Snippet name: oshi_detectVM - are we on a virtual machine?
Eternal ID of this version: #1019745/2
Text MD5: 68fbcc3e93776d63252bb580af152984
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-24 16:58:11
Source code size: 1117 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 223 / 269
Version history: 1 change(s)
Referenced in: [show references]