//获取主板物理网卡地址
public static string GetNetwork()
{
string strMac = null;
NetworkInterface[] fNetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in fNetworkInterfaces)
{
string fRegistryKey = "SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\" + adapter.Id + "\Connection";
RegistryKey rk = Registry.LocalMachine.OpenSubKey(fRegistryKey, false);
if (rk != null)
{
string fPnpInstanceID = rk.GetValue("PnpInstanceID", "").ToString();
//int fMediaSubType = Convert.ToInt32(rk.GetValue("MediaSubType", 0));
if (fPnpInstanceID.Length > 3 && fPnpInstanceID.Substring(0, 3) == "PCI")
{
if (adapter.GetPhysicalAddress() != null)
{
strMac = adapter.GetPhysicalAddress().ToString();
}
}
//else
//{
// if (fMediaSubType == 2)
// {
// //无线网卡
// }
// if (fMediaSubType == 1)
// {
// //虚拟网卡
// }
//}
}
}
if (strMac != null)
{
return strMac.ToLower();
}
else
{
return "";
}
}