您的位置:首页 > 其它

.Net如何得到Mac地址 和硬盘序列号

2010-06-10 10:47 330 查看
1.得到Mac地址

public static string GetMac(string clientip)
{
string mac = "";
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "nbtstat";
process.StartInfo.Arguments = "-a " + clientip;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
string output = process.StandardOutput.ReadToEnd();
int length = output.IndexOf("MAC Address =");
if (length > 0)
{
mac = output.Substring(length + 14, 17);
}
return mac;
}

2.得到硬盘序列号

public static string GetYP()
{
string _HDInfo = "";
ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc1 = cimobject1.GetInstances();
foreach (ManagementObject mo in moc1)
{
_HDInfo = (string)mo.Properties["Model"].Value;

}
return _HDInfo;
}

使用:

Console.WriteLine(GetMac("192.168.1.222"));
Console.WriteLine(GetYP());
Console.ReadLine();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: