def get_machine_name(net_config, nametype): """Return the ComputerName of this Mac.""" sys_info = SCDynamicStoreCopyValue(net_config, "Setup:/System") if sys_info: return sys_info.get(nametype) return subprocess.check_output( ["/usr/sbin/scutil", "--get", "ComputerName"], text=True).strip()
def get_domain_dns(): net_config = SCDynamicStoreCreate(None, 'active-directory', None, None) ad_info = SCDynamicStoreCopyValue(net_config, 'com.apple.opendirectoryd.ActiveDirectory') if ad_info is not None: return ad_info.get('DomainNameDns') else: raise NotBound
def get_domain_name(): '''Return current domain name''' dns_config = SCDynamicStoreCopyValue(None, 'State:/Network/Global/DNS') try: return dns_config.get('DomainName') except AttributeError: return None
def get_machine_name(net_config, nametype): """Return the ComputerName of this Mac.""" sys_info = SCDynamicStoreCopyValue(net_config, "Setup:/System") if sys_info: return sys_info.get(nametype) return subprocess.check_output( ['/usr/sbin/scutil', '--get', 'ComputerName'])
def get_domain_dns(): net_config = SCDynamicStoreCreate(None, 'active-directory', None, None) ad_info = SCDynamicStoreCopyValue( net_config, 'com.apple.opendirectoryd.ActiveDirectory') if ad_info is not None: return ad_info.get('DomainNameDns') else: raise NotBound
def domain(): if not bound(): raise NotBound net_config = SCDynamicStoreCreate(None, "active-directory", None, None) ad_info = SCDynamicStoreCopyValue(net_config, "com.apple.opendirectoryd.ActiveDirectory") if ad_info: return ad_info.get("DomainNameDns") else: return None
def fact(): """Returns Active Directory forest""" result = "None" net_config = SCDynamicStoreCreate(None, "net", None, None) d = SCDynamicStoreCopyValue(net_config, "com.apple.opendirectoryd.ActiveDirectory") if d: result = d.get("DomainForestName", None) return {factoid: result}
def fact(): '''Returns Active Directory forest''' result = 'None' net_config = SCDynamicStoreCreate(None, 'net', None, None) d = SCDynamicStoreCopyValue(net_config, 'com.apple.opendirectoryd.ActiveDirectory') if d: result = d.get('DomainForestName', None) return {factoid: result}
def fact(): """Returns Active Directory trust account""" result = "None" net_config = SCDynamicStoreCreate(None, "net", None, None) d = SCDynamicStoreCopyValue(net_config, "com.apple.opendirectoryd.ActiveDirectory") if d: result = d.get("TrustAccount", None) return {factoid: result}
def fact(): '''Returns Active Directory trust account''' result = 'None' net_config = SCDynamicStoreCreate(None, 'net', None, None) d = SCDynamicStoreCopyValue(net_config, 'com.apple.opendirectoryd.ActiveDirectory') if d: result = d.get('TrustAccount', None) return {factoid: result}
def fact(): """Returns the current dns domain""" result = "None" net_config = SCDynamicStoreCreate(None, "net", None, None) dns_info = SCDynamicStoreCopyValue(net_config, "State:/Network/Global/DNS") if dns_info: try: result = dns_info.get("DomainName", None) except KeyError: pass return {factoid: str(result)}
def fact(): '''Returns the current dns servers''' result = [] net_config = SCDynamicStoreCreate(None, "net", None, None) dns_info = SCDynamicStoreCopyValue(net_config, "State:/Network/Global/DNS") if dns_info and dns_info.get('ServerAddresses'): try: for i in dns_info['ServerAddresses']: result.append(i) except KeyError as err: pass return {factoid: result}
def fact(): """Returns the current dns servers""" proxies = "None" net_config = SCDynamicStoreCreate(None, "net", None, None) proxy_info = SCDynamicStoreCopyValue(net_config, "State:/Network/Global/Proxies") if proxy_info and proxy_info.get("ProxyAutoConfigURLString"): try: proxies = proxy_info["ProxyAutoConfigURLString"] except KeyError: pass return {factoid: proxies}
def fact(): '''Returns the current dns servers''' proxies = 'None' net_config = SCDynamicStoreCreate(None, "net", None, None) proxy_info = SCDynamicStoreCopyValue(net_config, "State:/Network/Global/Proxies") if proxy_info and proxy_info.get('ProxyAutoConfigURLString'): try: proxies = proxy_info['ProxyAutoConfigURLString'] except KeyError as err: pass return {factoid: proxies}
def fact(): """Returns the current search domains""" search_domains = None net_config = SCDynamicStoreCreate(None, "net", None, None) search_domains = [] dns_info = SCDynamicStoreCopyValue(net_config, "State:/Network/Global/DNS") if dns_info and dns_info.get("SearchDomains"): try: for i in dns_info["SearchDomains"]: search_domains.append(i) except KeyError: pass return {factoid: search_domains}
def SetCorpSetupKey(self, key, value): """Set key-value pair under the CORP_SETUP tree. Args: key: String, key to add value: string/integer if single value, dict if multiple values. Returns: Boolean, True if successful. Raises: SysconfigError: On failure (SCDynamicStore* does return False on failure, we don't get any better errors). """ long_key = '%s%s' % (CORP_SETUP, key) if SCDynamicStoreCopyValue(self.store, long_key) is not None: key_set = SCDynamicStoreSetValue(self.store, long_key, value) if key_set: logging.debug('Setting %s to value %s', long_key, value) return True else: raise SysconfigError('Failed setting %s with value %s' % (long_key, value)) else: add = SCDynamicStoreAddValue(self.store, long_key, value) if add: logging.debug('Adding %s with value %s', long_key, value) return True else: raise SysconfigError('Failed adding %s with value %s' % (long_key, value))
def get_interface(net_config): """Returns the active network interface of the Mac""" try: states = SCDynamicStoreCopyValue(net_config, "State:/Network/Global/IPv4") return states["PrimaryInterface"] except TypeError: pass
def fact(): '''Return True if there is a value for SystemConfiguration's Setup:/Network/BackToMyMac key''' return { 'backtomymac_configured': SCDynamicStoreCopyValue(None, 'Setup:/Network/BackToMyMac') is not None }
def get_primaryinterface(): '''Returns the active network interface of the Mac''' try: states = SCDynamicStoreCopyValue(net_config, "State:/Network/Global/IPv4") return states['PrimaryInterface'] except TypeError: return None
def get_ip(net_config, interface): '''Returns the IP address of the primary network interface''' addresses = SCDynamicStoreCopyValue( net_config, "State:/Network/Interface/%s/IPv4" % interface) try: return addresses['Addresses'][0] except TypeError: print TypeError exit(1)
def fact(): '''Returns the ComputerName''' result = 'None' net_config = SCDynamicStoreCreate(None, "net", None, None) sys_info = SCDynamicStoreCopyValue(net_config, "Setup:/System") result = sys_info['ComputerName'] return {factoid: result}
def fact(): """Returns the ComputerName""" result = "None" net_config = SCDynamicStoreCreate(None, "net", None, None) sys_info = SCDynamicStoreCopyValue(net_config, "Setup:/System") result = sys_info["ComputerName"] return {factoid: result}
def fact(): '''Returns the value of the hostname of this Mac''' result = 'None' net_config = SCDynamicStoreCreate(None, "net", None, None) sys_info = SCDynamicStoreCopyValue(net_config, "Setup:/System") result = sys_info['HostName'] return {factoid: result}
def get_info(net_config, interface): """Returns the IP address of the primary network interface""" addresses = SCDynamicStoreCopyValue( net_config, f"State:/Network/Interface/{interface}/IPv4" ) try: return addresses["Addresses"][0] except TypeError: pass
def searchnodes(): if not bound(): raise NotBound net_config = SCDynamicStoreCreate(None, 'directory-nodes', None, None) nodes = SCDynamicStoreCopyValue(net_config, 'com.apple.opendirectoryd.node:/Search') if nodes: return list(nodes) else: return None
def fact(): """Returns the value of the hostname of this Mac""" result = "None" net_config = SCDynamicStoreCreate(None, "net", None, None) sys_info = SCDynamicStoreCopyValue(net_config, "Setup:/System") result = sys_info["HostName"] return {factoid: result}
def fact(): """Returns the directory search node info""" result = "None" net_config = SCDynamicStoreCreate(None, "net", None, None) search_node = SCDynamicStoreCopyValue( net_config, "com.apple.opendirectoryd.node:/Contacts") result = search_node[0] return {factoid: result}
def fact(): '''Check to see if GlobalProtect VPN is active.''' result = False net_config = SCDynamicStoreCreate(None, "net", None, None) vpn = SCDynamicStoreCopyValue(net_config, 'State:/Network/Service/gpd.pan/DNS') if vpn is not None: result = True return {factoid: result}
def fact(): '''Returns the primary interface of this Mac''' primary_interface = None net_config = SCDynamicStoreCreate(None, "net", None, None) try: states = SCDynamicStoreCopyValue(net_config, "State:/Network/Global/IPv4") primary_interface = states['PrimaryInterface'] except TypeError: pass return {factoid: primary_interface}
def fact(): '''Returns the mac address of this Mac''' net_config = SCDynamicStoreCreate(None, "net", None, None) states = SCDynamicStoreCopyValue(net_config, "State:/Network/Global/IPv4") primary_interface = states["PrimaryInterface"] primary_device = [ x for x in SCNetworkInterfaceCopyAll() if SCNetworkInterfaceGetBSDName(x) == primary_interface ][0] primary_MAC = SCNetworkInterfaceGetHardwareAddressString(primary_device) return {factoid: primary_MAC}
def fact(): '''Returns the directory search node info''' result = 'None' net_config = SCDynamicStoreCreate(None, "net", None, None) contacts_node = SCDynamicStoreCopyValue( net_config, "com.apple.opendirectoryd.node:/Contacts" ) if contacts_node: result = contacts_node[0] return {factoid: result}
def get_iface(net_config): """Returns the primary interface of this Mac""" iface = None try: states = SCDynamicStoreCopyValue(net_config, "State:/Network/Global/IPv4") iface = states["PrimaryInterface"] except TypeError: pass return iface
def get_domain_name(): '''Return current domain name''' dns_config = SCDynamicStoreCopyValue(None, 'State:/Network/Global/DNS') return dns_config.get('DomainName')