def main(): network_interfaces = SCNetworkInterfaceCopyAll() print get_networkinterfacelist(network_interfaces) prefs = SCPreferencesCreate(None, 'foo', None) network_services = SCNetworkServiceCopyAll(prefs) print get_networkservices(network_services)
def fact(): '''Return the value of the computername of this Mac''' network_interfaces = SCNetworkInterfaceCopyAll() interfaces = [] for interface in network_interfaces: interfaces.append(SCNetworkInterfaceGetLocalizedDisplayName(interface)) return {factoid: interfaces}
def get_interface_info(_fd, iface): r = SCNetworkInterfaceCopyAll() if iface: for scnetworkinterface in r: if str(SCNetworkInterfaceGetBSDName(scnetworkinterface))==iface: return do_get_interface_info(scnetworkinterface) elif len(r)==1: return do_get_interface_info(r[0]) return {}
def interfaces(): '''Returns a list of all network interface names''' network_interfaces = SCNetworkInterfaceCopyAll() interfaces = {} for interface in network_interfaces: interfaces[SCNetworkInterfaceGetLocalizedDisplayName(interface)] = ( SCNetworkInterfaceGetBSDName(interface), SCNetworkInterfaceGetHardwareAddressString(interface)) return interfaces
def fact(): """Returns a list of all network interface names""" network_interfaces = SCNetworkInterfaceCopyAll() interfaces = {} for interface in network_interfaces: interfaces[SCNetworkInterfaceGetLocalizedDisplayName(interface)] = ( SCNetworkInterfaceGetBSDName(interface), SCNetworkInterfaceGetHardwareAddressString(interface), ) return {factoid: str(interfaces)}
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 get_wifi_interface(): """Returns the name of the wifi interface.""" network_interfaces = SCNetworkInterfaceCopyAll() interfaces = {} for interface in network_interfaces: interfaces[SCNetworkInterfaceGetLocalizedDisplayName(interface)] = ( SCNetworkInterfaceGetBSDName(interface), SCNetworkInterfaceGetHardwareAddressString(interface), ) wifi_interface = None try: wifi_interface = interfaces["Wi-Fi"][0] except KeyError: pass return wifi_interface
def fact(): """Return the active network interfaces""" result = [] interfaces = [ SCNetworkInterfaceGetBSDName(i) for i in SCNetworkInterfaceCopyAll() ] for i in interfaces: try: active = subprocess.check_output( ["/usr/sbin/ipconfig", "getifaddr", i]).strip() if active: result.append(i) except subprocess.CalledProcessError: continue return {factoid: result}
def get_en0_mac(): '''Returns the MAC layer address of en0''' for interface in SCNetworkInterfaceCopyAll(): if SCNetworkInterfaceGetBSDName(interface) == "en0": return SCNetworkInterfaceGetHardwareAddressString(interface) return None
def main(): r = SCNetworkInterfaceCopyAll() print("%i interfaces:" % len(r)) for scnetworkinterface in r: info = do_get_interface_info(scnetworkinterface) print(info)
def update_dhcp(interface): interfaces = SCNetworkInterfaceCopyAll() for i in interfaces: if SCNetworkInterfaceGetBSDName(i) == interface: return SCNetworkInterfaceForceConfigurationRefresh(i) return False