如何判断当前程序是否运行在虚拟机中?


=Start=

缘由:

突然想到的一个点,觉得有必要收集整理一下,方便以后使用。

正文:

参考解答:

这里只简单谈一谈应用层面的判断,太底层的我也不会、也不了解,就不说了,如果有懂的还请多指点一下。

# Windows

systeminfo | findstr /i model
wmic baseboard get manufacturer,product
Win+R => msinfo32 => 'System Manufacturer'

# Mac 

ioreg -l | grep -e 'Manufacturer'

# Linux

核心思路基本上就是通过在 dmesg输出或是/proc/cpuinfo 等文件中查找关键字来进行判断(不同版本可能不一样,所以可以借助一些工具或脚本来加速查找,比如 virt-what)。

dmidecode -t system | egrep -i 'manufacturer|product'
dmidecode -s system-product-name

sudo lshw -class system

dmesg | egrep -i 'hypervisor|vmware'

systemd-detect-virt

grep -q '^flags.*hypervisor' /proc/cpuinfo

大致内容如上,想到了再补充。

参考链接:

=END=


《“如何判断当前程序是否运行在虚拟机中?”》 有 8 条评论

  1. 如何根据机器的mac地址来判别该机器是否为vmware的虚拟机
    How to recognise a VMware’s virtual machine by its MAC address?
    https://macaddress.io/faq/how-to-recognise-a-vmwares-virtual-machine-by-its-mac-address
    `
    # Range or Prefix Vendor Virtual Machine
    1 00:50:56 VMWare VMware vSphere, VMware Workstation, VMware ESX Server
    2 00:50:56:80:00:00 → 00:50:56:BF:FF:FF VMWare VMware vSphere managed by vCenter Server
    3 00:0C:29 VMWare Standalone VMware vSphere, VMware Workstation, VMware Horizon
    4 00:05:69 VMWare VMware ESX, VMware GSX Server
    5 00:1C:14 VMWare VMWare
    `

  2. How to recognise an Oracle Virtual machine by its MAC address?
    https://macaddress.io/faq/how-to-recognise-an-oracle-virtual-machine-by-its-mac-address
    `
    # Range or Prefix Vendor Virtual Machine
    1 08:00:27 Pcs Systemtechnik GmbH Oracle VirtualBox 5.2
    2 52:54:00 (Exact MAC: 52:54:00:C9:C7:04) N/A Oracle VirtualBox 5.2 + Vagrant
    3 00:21:F6 Oracle Corp Oracle VirtualBox 3.3
    4 00:14:4F Oracle Corp Oracle VM Server for SPARC
    5 00:0F:4B Oracle Corp Oracle Virtual Iron 4
    `

  3. 7 ways to find your MAC address in Windows
    https://www.digitalcitizen.life/4-ways-learn-mac-address-windows-7-windows-81/
    `
    # Windows 下获取mac地址的命令
    getmac

    wmic nic where PhysicalAdapter=True get MACAddress,Name

    ipconfig /all

    ==
    1. Find your MAC address using the getmac command in Terminal, PowerShell, or Command Prompt
    2. How to find your MAC address with the “get-netadapter” command in PowerShell
    3. Get your MAC address by running the ipconfig command in Windows Terminal, PowerShell, or Command Prompt
    4. How to find your MAC address using the “wmic nic get” command in Windows Terminal, PowerShell, and Command Prompt
    5. How to get your MAC address in Windows using the Settings app
    __1. Identify your MAC address using Settings in Windows 11
    __2. Identify your MAC address using Settings in Windows 10
    6. Find the MAC address of any of your network adapters using System Information
    7. How to find the MAC address of the active network adapter from the Control Panel
    `

    Get mac address from command line (CMD)
    https://www.windows-commandline.com/get-mac-address-command-line/

    Windows: Command to Find MAC Address
    https://www.technipages.com/windows-find-mac-address

  4. 根据设备的mac地址来判别该设备的网卡是属于哪家公司的

    Devices with MAC addresses that start with 00-50-56 were manufactured by VMware, Inc.
    https://www.cleancss.com/mac-lookup/00-50-56
    `
    以下列字符串开头的MAC地址列表就是属于 VMware 公司的:
    Related MAC Addresses:
    00-1C-14
    00-0C-29
    00-05-69
    `

    Devices with MAC addresses that start with 00-10-E0 were manufactured by Oracle Corporation
    https://www.cleancss.com/mac-lookup/00-10-E0
    `
    以下列字符串开头的MAC地址列表就是属于 Oracle 公司的(virtual box等):
    Related MAC Addresses:
    00-14-4F
    08-00-20
    00-0F-4B
    00-03-BA
    00-00-7D
    00-13-97
    00-A0-A4
    2C-C2-60
    00-21-28
    00-10-4F
    00-07-82
    00-21-F6
    00-20-F2
    00-01-5D
    `

  5. OUI Lookup Tool
    https://rst.im/oui/00-50-56-C0-00-08
    https://rst.im/oui/VMware,%20Inc.
    https://rst.im/oui/Oracle%20Corporation
    `
    Manufacturer(VMware, Inc.):
    MAC Address Prefix 001C14 00-1C-14 00:1C:14
    MAC Address Prefix 005056 00-50-56 00:50:56
    MAC Address Prefix 000C29 00-0C-29 00:0C:29
    MAC Address Prefix 000569 00-05-69 00:05:69

    Manufacturer(Oracle Corporation):
    MAC Address Prefix 0021F6 00-21-F6 00:21:F6
    MAC Address Prefix 002128 00-21-28 00:21:28
    MAC Address Prefix 00A0A4 00-A0-A4 00:A0:A4
    MAC Address Prefix 001397 00-13-97 00:13:97
    MAC Address Prefix 000F4B 00-0F-4B 00:0F:4B
    MAC Address Prefix 00104F 00-10-4F 00:10:4F
    MAC Address Prefix A8698C A8-69-8C A8:69:8C
    MAC Address Prefix 2CC260 2C-C2-60 2C:C2:60
    MAC Address Prefix 00144F 00-14-4F 00:14:4F
    MAC Address Prefix 080020 08-00-20 08:00:20
    MAC Address Prefix 000782 00-07-82 00:07:82
    MAC Address Prefix 00007D 00-00-7D 00:00:7D
    MAC Address Prefix 0003BA 00-03-BA 00:03:BA
    MAC Address Prefix 00015D 00-01-5D 00:01:5D
    MAC Address Prefix 0010E0 00-10-E0 00:10:E0
    MAC Address Prefix 0020F2 00-20-F2 00:20:F2
    `

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注