获取计算机名称,IP,MAC地址:
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();
}