=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
大致内容如上,想到了再补充。
参考链接:
- How to check if a machine is physical or virtual
https://shabaztech.com/check-machine-physical-virtual/ - How do I know if I’m working on a Virtual Machine or not?
- https://superuser.com/questions/806209/is-there-any-way-to-identify-if-my-server-is-hyperv-vm-or-a-physical-machine
- Determining if you are running on a virtualized platform (1005436)
- https://stackoverflow.com/questions/39533/how-to-identify-that-youre-running-under-a-vm
- https://stackoverflow.com/questions/28529633/how-to-detect-if-mac-os-x-is-being-run-inside-a-virtual-machine
- https://unix.stackexchange.com/questions/3685/find-out-if-the-os-is-running-in-a-virtual-environment
- https://unix.stackexchange.com/questions/89714/easy-way-to-determine-virtualization-technology
- https://www.ostechnix.com/check-linux-system-physical-virtual-machine/
=END=
《“如何判断当前程序是否运行在虚拟机中?”》 有 4 条评论
如何根据机器的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
`
如何获取Windows主机的主机序列号
https://support.microsoft.com/en-us/topic/how-to-find-computer-serial-number-7ceeffe0-1028-840e-dce9-d41634d54cff
`
wmic bios get serialnumber
默认情况下,虚拟机里的系统序列号是下面这种格式,可以简单用来判断当前运行的系统是不是跑在虚拟机里面:
VMware-xx yy zz…
`
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
`
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