Determine when running in a virtual machine

后端 未结 10 452
遇见更好的自我
遇见更好的自我 2020-12-12 11:39

Is there an official way for an application to determine if it is running in VMWare or Virtual PC (or whatever Microsoft is calling it now)? The code I have seen i

10条回答
  •  有刺的猬
    2020-12-12 12:14

    I've had good luck with just looking at the MAC address as all manufacturers are given a block and the first 3 parts are unique to them.

    //look at the MAC address and determine if it's a Virtual Machine
    $temp = preg_split("/\s+/",exec("/sbin/ifconfig -a eth0 2>&1 | /bin/grep HWaddr"), -1, PREG_SPLIT_NO_EMPTY);
    //Virtual Box MACs all start with '08:00:27:xx:xx:xx'
    if (strpos($temp[4], '08:00:27') !== false) $_SESSION['DEVELOPMENT'] = true;  
    

提交回复
热议问题