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

49
LINES

< > BotCompany Repo | #1019744 // OSHI Detect VM Spike (seems to work, tested on VirtualBox and real OSes)

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 7696K of libraries. Click here for Pure Java version (2203L/15K).

1  
!7
2  
3  
p {
4  
  // Set up constants
5  
  new SS vmMap;
6  
  vmMap.put("00:50:56", "VMware ESX 3");
7  
  vmMap.put("00:0C:29", "VMware ESX 3");
8  
  vmMap.put("00:05:69", "VMware ESX 3");
9  
  vmMap.put("00:03:FF", "Microsoft Hyper-V");
10  
  vmMap.put("00:1C:42", "Parallels Desktop");
11  
  vmMap.put("00:0F:4B", "Virtual Iron 4");
12  
  vmMap.put("00:16:3E", "Xen or Oracle VM");
13  
  vmMap.put("08:00:27", "Sun xVM VirtualBox");
14  
15  
  String[] vmArray = { "Linux KVM", "Linux lguest", "OpenVZ", "Qemu", "Microsoft Virtual PC",
16  
    "VMWare", "linux-vserver", "Xen", "FreeBSD Jail", "OpenVZ Host", "VirtualBox", "Parallels",
17  
    "Linux Containers", "LXC" };
18  
19  
  HardwareAbstractionLayer hw = oshi_hardware();
20  
21  
  // Try well known MAC addresses
22  
  NetworkIF[] nifs = hw.getNetworkIFs();
23  
  boolean isvm = false;
24  
  for (NetworkIF nif : nifs) {
25  
      String mac = nif.getMacaddr().substring(0, 8).toUpperCase();
26  
      if (vmMap.containsKey(mac)) {
27  
          print("On a VM: " + vmMap.get(mac));
28  
          isvm = true;
29  
          break;
30  
      }
31  
  }
32  
33  
  // Try well known models
34  
  if (!isvm) {
35  
      String model = hw.getComputerSystem().getModel();
36  
      print(model);
37  
      for (String vm : vmArray) {
38  
          if (model.contains(vm)) {
39  
              print("On a VM: " + vm);
40  
              isvm = true;
41  
              break;
42  
          }
43  
      }
44  
  }
45  
46  
  if (!isvm) {
47  
      print("Couldn't detect VM");
48  
  }
49  
}

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: #1019744
Snippet name: OSHI Detect VM Spike (seems to work, tested on VirtualBox and real OSes)
Eternal ID of this version: #1019744/2
Text MD5: fce2fbaf485c414d10027e09f205d113
Transpilation MD5: 6b879d1739eba61988520253736c8c23
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-24 16:37:23
Source code size: 1407 bytes / 49 lines
Pitched / IR pitched: No / No
Views / Downloads: 345 / 974
Version history: 1 change(s)
Referenced in: [show references]