var managementClass = new ManagementClass("Win32_NetworkAdapterConfiguration"); var managementObjectCollection = managementClass.GetInstances(); foreach (var managementObject in managementObjectCollection.OfType<ManagementObject>()) { using (managementObject) { if ((bool) managementObject["IPEnabled"]) { if (managementObject["MacAddress"] == null) { return string.Empty; } return managementObject["MacAddress"].ToString().ToUpper(); } } }
输出的格式是 5A:15:31:73:B0:9F 同时输出是一个网卡
c# - .NET Core 2.x how to get the current active local network IPv4 address? - Stack Overflow