Hi @Dani_S ,
The code you provided retrieves the MAC (Media Access Control) address of the network interface that is currently operational. It utilizes the NetworkInterface.GetAllNetworkInterfaces()
method to get all network interfaces available on the system, then filters them using a LINQ query to select only those interfaces with OperationalStatus
equal to OperationalStatus.Up
, indicating they are operational and can transmit data.
Once it finds the first matching interface, it retrieves its physical address using nic.GetPhysicalAddress(), converts it to a string, and returns it. If no matching interface is found or if the MAC address is empty or null, it returns null.
This function could be used in scenarios where you need to identify the MAC address of the primary network interface for network-related tasks or for device identification purposes.
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.