Read MAC Address from network adapter in .NET

前端 未结 7 1995
梦谈多话
梦谈多话 2020-11-29 07:02

I\'d like to be able to read the mac address from the first active network adapter using VB.net or C# (using .NET 3.5 SP1) for a winform application

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 07:23

    using Linq..
    
    using System.Net.NetworkInformation;
    ..
    
    NetworkInterface nic =
        NetworkInterface.GetAllNetworkInterfaces()
        .Where(n => n.OperationalStatus == OperationalStatus.Up).FirstOrDefault();
    
    if (nic != null)
        return nic.GetPhysicalAddress().ToString();
    

提交回复
热议问题