getOSCongif
using System;
using System.Management;
using System.Net;
namespace ConsoleApplication1
{
public class GetOSCongif
{
public GetOSCongif(){}
public string GetCPUConfig()
{
try
{
string cpuInfo = "";//cpu序列号
ManagementClass cimobject = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = cimobject.GetInstances();
foreach (ManagementObject mo in moc)
{
cpuInfo = mo.Properties["ProcessorId"].ToString();
}
string outPutStr = "CPU:{0}";
outPutStr = string.Format(outPutStr, cpuInfo);
return (outPutStr);
}
catch (Exception e)
{
return (e.ToString());
}
}
public string GetMACConfig() {
try
{
string mac = "";
ManagementClass mc;
string hostInfo = Dns.GetHostName();
mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (mo["IPEnabled"].ToString() == "True")
{
mac = mo["MacAddress"].ToString();
}
}
string outPutStr = "MAC地址:{0}";
outPutStr = string.Format(outPutStr, mac);
return(outPutStr);
}
catch (Exception e)
{
return(e.ToString());
}
}
public string GetIPConfig() {
try
{
string ip = "";
string hostInfo = Dns.GetHostName();
System.Net.IPAddress[] addressList = Dns.GetHostEntry(Dns.GetHostName()).AddressList;
for (int i = 0; i < addressList.Length; i++)
{
ip = addressList[i].ToString();
}
string outPutStr = "IP:{0}";
outPutStr = string.Format(outPutStr, ip);
return(outPutStr);
}
catch (Exception e)
{
return(e.ToString());
}
}
}
}