c# 通過NetworkInterface讀取網絡卡Mac
阿新 • • 發佈:2019-01-28
using System.Net.NetworkInformation;
///<summary>
/// 通過NetworkInterface讀取網絡卡Mac///</summary>
///<returns></returns>
public List<string> GetMacByNetworkInterface()
{
List<string> macs = new List<string>();
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface ni in interfaces)
{
if (ni.GetPhysicalAddress().ToString() != "")
{
macs.Add(ni.GetPhysicalAddress().ToString());
}
}
return macs;
}