Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Programmatically determine if an OS X device is a VM in python by available CPU features
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