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);
新闻热点
疑难解答