コード例 #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()
コード例 #2
0
ファイル: __init__.py プロジェクト: Shufflepuck/pymacad
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
コード例 #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
コード例 #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'])
コード例 #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
コード例 #6
0
ファイル: __init__.py プロジェクト: kylecrawshaw/pymacad
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
コード例 #7
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}
コード例 #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}
コード例 #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}
コード例 #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}
コード例 #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)}
コード例 #12
0
ファイル: dns_servers.py プロジェクト: ulte/unearth
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}
コード例 #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}
コード例 #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}
コード例 #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}
コード例 #16
0
ファイル: systemconfig.py プロジェクト: vmiller/imagr
    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))
コード例 #17
0
ファイル: network_info.py プロジェクト: forvitinn/Hello-IT
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
コード例 #18
0
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
    }
コード例 #19
0
ファイル: renew_dhcp_lease.py プロジェクト: nathan8299/pylab
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
コード例 #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)
コード例 #21
0
ファイル: computername.py プロジェクト: ulte/unearth
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}
コード例 #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}
コード例 #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}
コード例 #24
0
ファイル: network_info.py プロジェクト: forvitinn/Hello-IT
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
コード例 #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
コード例 #26
0
ファイル: hostname.py プロジェクト: jesusoctavioas/unearth
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}
コード例 #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}
コード例 #28
0
ファイル: vpn_active.py プロジェクト: ulte/unearth
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}
コード例 #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}
コード例 #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}
コード例 #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}
コード例 #32
0
ファイル: cidr.py プロジェクト: jesusoctavioas/unearth
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
コード例 #33
0
ファイル: autoconfig.py プロジェクト: munki/munki
def get_domain_name():
    '''Return current domain name'''
    dns_config = SCDynamicStoreCopyValue(None, 'State:/Network/Global/DNS')
    return dns_config.get('DomainName')