Exemplo n.º 1
0
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()
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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'])
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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}
Exemplo n.º 8
0
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}
Exemplo n.º 9
0
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}
Exemplo n.º 10
0
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}
Exemplo n.º 11
0
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)}
Exemplo n.º 12
0
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}
Exemplo n.º 13
0
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}
Exemplo n.º 14
0
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}
Exemplo n.º 15
0
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}
Exemplo n.º 16
0
    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))
Exemplo n.º 17
0
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
    }
Exemplo n.º 19
0
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
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
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}
Exemplo n.º 22
0
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}
Exemplo n.º 23
0
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}
Exemplo n.º 24
0
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
Exemplo n.º 25
0
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
Exemplo n.º 26
0
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}
Exemplo n.º 27
0
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}
Exemplo n.º 28
0
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}
Exemplo n.º 29
0
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}
Exemplo n.º 30
0
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}
Exemplo n.º 31
0
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}
Exemplo n.º 32
0
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
Exemplo n.º 33
0
def get_domain_name():
    '''Return current domain name'''
    dns_config = SCDynamicStoreCopyValue(None, 'State:/Network/Global/DNS')
    return dns_config.get('DomainName')