asp.net core 获取 MacAddress 地址方法示例(2)

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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdsgfy.html