如何判断我是否在 VMWARE 虚拟机(来自 Linux)中运行?
我有一台 VMWARE ESX 服务器。 我在该服务器上运行了 Redhat VM。 如果我在虚拟机中运行,我需要一种以编程方式测试的方法。 理想情况下,我想知道如何从 Perl 执行此操作。
I have a VMWARE ESX server. I have Redhat VMs running on that server. I need a way of programatically testing if I'm running in a VM. Ideally, I'd like to know how to do this from Perl.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
请参阅“从应用程序检测虚拟化操作系统?”的答案。
See the answer to "Detect virtualized OS from an application?".
您不应该 100% 依赖任何方法,因为它们是未记录的功能/错误 - 它们适用于某些主机操作系统和某些虚拟化解决方案,但不能保证它们会继续工作; 事实上,虚拟化的全部意义就是尽可能与真实金属没有区别。 考虑到这一点,蓝色药丸红色药丸(在接受的答案中提到这个类似的问题)似乎暂时有效。
You shouldn't 100% depend on any method, as they are undocumented features/bugs - they work on some host OSes and some virtualization solutions, but there is no guarantee that they will continue working; indeed, the whole point of virtualization is to be as undistinguishable from real metal as possible. With this in mind, the blue pill red pill (which is mentioned in the accepted answer to this similar question) seems to work ... for now.
VMWare 有几个 SDK,其中包括 适用于 Perl 的 SDK。
VMWare has a couple of SDK's, including an SDK for Perl.
我认为(取决于 esx 的版本)您可以检查网卡的 MAC 地址。 在 VMWare NIC 中运行的虚拟机将分配给 VMWare 的制造商字符串,而不是物理 NIC MAC。 (我们试图将 MAC 欺骗到 VM 许可证服务器,而较新的版本不允许您这样做。)此外,这并不能保证您不会在带有欺骗性的 NIC 看起来像 VMWare 的物理机器上运行,但无论如何,在大多数情况下,这样做都是一件奇怪的事情。
I think (depending on the version of esx) you can inspect at the MAC address of the NIC. VMs running in VMWare NIC will have a manufacturer string assigned to VMWare, no the physical NIC MAC. (We were trying to spoof the MAC to VM a license server and newer versions won't let you do it.) Also, this won't guarantee you aren't running on a physical box with a NIC spoofed to look like VMWare, but that would be an odd thing to do in most circumstances anyway.
运行以下命令:
它应该显示如下内容:
Run the following command:
It should show something like this: