-
-
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.
This file contains hidden or 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
#!/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') |
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
Updating this to work with Addigy Custom Facts.