获取计算机名称,IP,MAC地址

+展开
-C#
       private void button1_Click_1(object sender, System.EventArgs e)
        {
            string s="",mac=""
            //
            //name
            //
            string hostInfo = Dns.GetHostName();            

            //
            //IP
            System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;  
            for (int i = 0; i < addressList.Length; i ++) 
            { 
                s += addressList[i].ToString(); 
            } 
            //
            //mac
            //


            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();                    
            }


            txtName.Text=hostInfo;
            txtIp.Text=s;
            txtMac.Text=mac;


            button1.Enabled=false;
            button2.Focus();

        } 


http://www.cnblogs.com/tuyile006/archive/2006/12/21/598945.html

加支付宝好友偷能量挖...


评论(0)网络
阅读(102)喜欢(0)Asp.Net/C#/WCF