Skip to content

Instantly share code, notes, and snippets.

@AndrewWCarson
Forked from pudquick/macvm_detect.py
Last active February 12, 2019 15:08
Show Gist options
  • Save AndrewWCarson/014bfa84e9aef90de874364ca9daeabc to your computer and use it in GitHub Desktop.
Save AndrewWCarson/014bfa84e9aef90de874364ca9daeabc to your computer and use it in GitHub Desktop.
Addigy boolean Custom Fact that detects whether the machine is a VM based on a script from Mike Lynn <3.
#!/bin/python
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(' ')
if is_mac_vm():
print('true')
else:
print('false')
@AndrewWCarson
Copy link
Author

Updating this to work with Addigy Custom Facts.

@AndrewWCarson
Copy link
Author

Okay. 'Is VM.py' is a Custom Fact for Addigy that will return whether the device is a VM or a real Mac. Not compatible with Linux obviously. I've only tested on 10.14. YMMV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment