vs2003 下获取mac网卡地址函数

//这里唯一注意下的就是Management在vs2003下不是默认的,需要引用一下System.Management.dll就ok了。

using System.Net;
using System.Management;

 

//获取mac地址
  public string GetCustomerMac()
  {
   string macInfo = "";
   string s="",mac="";                      

   string hostInfo = Dns.GetHostName();                         

   System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;                     

   for (int i = 0; i < addressList.Length; i ++)                

   {             

    s += addressList[i].ToString();                                   }                                            ManagementClass mc;         

   mc=new ManagementClass("Win32_NetworkAdapterConfiguration");
   ManagementObjectCollection moc=mc.GetInstances();                      

   foreach(ManagementObject mo in moc)                    

   {         

    if(mo["IPEnabled"].ToString()=="True")                    
     mac=mo["MacAddress"].ToString();         
   }                 

   macInfo = mac;
   return macInfo;
  }

posted @ 2008-10-04 10:43  彭成刚  阅读(368)  评论(0编辑  收藏  举报