Skip to content

Instantly share code, notes, and snippets.

@pudquick
Created August 4, 2016 21:44
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pudquick/8107bb7b6e8d63eaddec7042c081e656 to your computer and use it in GitHub Desktop.
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
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