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).

!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");
  }
}

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: 344 / 970
Version history: 1 change(s)
Referenced in: