string s="",Mac="";
// 得到主機名
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();
}
Console.Write("主機名:" + hostInfo);
Console.Write("IP地址:" + s);
Console.Write("MAC地址:" + Mac);