using System.Net;
using System.Management;
//计算机名
string MachineName = System.Environment.MachineName;
//域名
string UserDomainName = System.Environment.UserDomainName;
//用户名
string UserName = System.Environment.UserName;
//当前Mac地址
string MacAddress = ManagementSystemInfo.GetActivatedAdaptorMacAddress();
/// <summary>
/// 获得当前机器的活动中Mac地址,若无联网则返回空""
/// </summary>
/// <returns>mac地址,例如:18:03:73:AE:38:0D</returns>
public static string GetActivatedAdaptorMacAddress()
{
string mac = "";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (mo["IPEnabled"].ToString() == "True")
{
mac = mo["MacAddress"].ToString();
}
}
return mac;
}