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 get_networkinterfacelist(network_interfaces): '''Returns a list of all network interface names''' d = {} for interface in network_interfaces: bsdName = SCNetworkInterfaceGetBSDName(interface) if 'en' in bsdName: d[SCNetworkInterfaceGetLocalizedDisplayName(interface)] = ( bsdName, SCNetworkInterfaceGetHardwareAddressString(interface)) return d
def service(self): """ Returns the service relating to self.interface """ prefs = SCPreferencesCreate(kCFAllocatorDefault, 'PRG', None) # Fetch the list of services for serviceRef in SCNetworkServiceCopyAll(prefs): interface = SCNetworkServiceGetInterface(serviceRef) if self.interface == SCNetworkInterfaceGetBSDName(interface): return serviceRef return None
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 do_get_interface_info(scnetworkinterface): info = {} bsdname = SCNetworkInterfaceGetBSDName(scnetworkinterface) if bsdname: info["name"] = str(bsdname) hw = SCNetworkInterfaceGetHardwareAddressString(scnetworkinterface) if hw: info["hardware-address"] = str(hw) t = SCNetworkInterfaceGetInterfaceType(scnetworkinterface) if t: info["adapter-type"] = str(t) #SCNetworkInterfaceGetLocalizedDisplayName p = SCNetworkInterfaceGetSupportedProtocolTypes(scnetworkinterface) if p: info["protocols"] = tuple(str(x) for x in p) return info
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(): '''This function is very similar to our fix but instead of performing any systematic changes will read the information and report it to jamf as an extension attribute.''' eap8021x_bundle = NSBundle.bundleWithPath_( '/System/Library/PrivateFrameworks/EAP8021X.framework') # EAP Functions from @mosen's meap project (See above for link) eapol_functions = [ ('EAPOLClientConfigurationGetTypeID', 'Q'), ('EAPOLClientProfileGetTypeID', 'Q'), ('EAPOLClientItemIDGetTypeID', 'Q'), ('EAPOLClientConfigurationCreate', '^{EAPOLClientConfigurationRef=}^{__CFAllocator=}'), ('EAPOLClientProfileGetUserDefinedName', '@^{EAPOLClientProfileRef=}'), ('EAPOLClientConfigurationGetSystemProfile', '^{EAPOLClientProfileRef=}' '^{EAPOLClientConfigurationRef=}@'), ('EAPOLClientConfigurationSetSystemProfile', 'Z^{EAPOLClientConfigurationRef=}@' '^{EAPOLClientProfileRef=}'), ('EAPOLClientConfigurationSave', 'Z^{EAPOLClientConfigurationRef=}') ] objc.loadBundleFunctions(eap8021x_bundle, globals(), eapol_functions) # CF Types to be loaded also from @mosen's meap project cf_types = [ ('EAPOLClientConfigurationRef', '^{EAPOLClientConfigurationRef=}', EAPOLClientConfigurationGetTypeID()), ('EAPOLClientProfileRef', '^{EAPOLClientProfileRef=}', EAPOLClientProfileGetTypeID()), ('EAPOLClientItemIDRef', '^{EAPOLClientItemIDRef=}', EAPOLClientItemIDGetTypeID()), ] for item in cf_types: objc.registerCFSignature(*item) # Define blank list to be used to gather EAPOL information on # Ethernet interfaces interface_list = [] prefs = SCPreferencesCreate(None, "python", None) services = SCNetworkServiceCopyAll(prefs) # Poll through the interfaces and make a list of the true Ethernet # adapters on the system for interface in ethernet_services(services): interface_list.append(SCNetworkInterfaceGetBSDName(interface)) # For loop to iterate through our Ethernet adapters and determine if they # have the system profile we are looking for and apply it to any other # Ethernet interfaces that don't have it applied. Change "Ethernet(COE)" # to whatever your 802.1x profile is called in Network Preferences. # Default in jamf is sadly "Network" for ethernet in interface_list: cfg = EAPOLClientConfigurationCreate(None) look_for_cfg = EAPOLClientConfigurationGetSystemProfile(cfg, ethernet) if look_for_cfg is not None: if EAPOLClientProfileGetUserDefinedName( look_for_cfg) == 'Ethernet(COE)': for ethernet in interface_list: if EAPOLClientConfigurationGetSystemProfile( cfg, ethernet) == look_for_cfg: continue else: EAPOLClientConfigurationSetSystemProfile( cfg, ethernet, look_for_cfg) EAPOLClientConfigurationSave(cfg)
def update_dhcp(interface): interfaces = SCNetworkInterfaceCopyAll() for i in interfaces: if SCNetworkInterfaceGetBSDName(i) == interface: return SCNetworkInterfaceForceConfigurationRefresh(i) return False