Created
August 4, 2016 21:44
-
-
Save pudquick/8107bb7b6e8d63eaddec7042c081e656 to your computer and use it in GitHub Desktop.
Programmatically determine if an OS X device is a VM in python by available CPU features
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ctypes import CDLL, c_uint, byref, create_string_buffer | |
libc = CDLL('/usr/lib/libc.dylib') | |
def sysctl(name): | |
size = c_uint(0) | |
libc.sysctlbyname(name, None, byref(size), None, 0) | |
buf = create_string_buffer(size.value) | |
libc.sysctlbyname(name, buf, byref(size), None, 0) | |
return buf.value | |
def is_mac_vm(): | |
return 'VMM' in sysctl('machdep.cpu.features').split(' ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment