c# 获取服务器操作系统信息

系统运维 waitig 495℃ 百度已收录 0评论

软件部署到多个服务器上时,我们需要做一些校验,比如有效期的校验,这就可能关联很多操作系统的物理参数,通过以下

方法可以获取一些相关参数,然后后通过UPD发包到控制中心,同时还可以做一些其他处理:

string cpuInfo = "";
            string addressWidth = "";

            //cpu序列号
            ManagementClass cimobject = new ManagementClass("Win32_Processor");
            ManagementObjectCollection moc = cimobject.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                addressWidth = mo.Properties["AddressWidth"].Value.ToString();

                cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
                Console.WriteLine("cpu序列号:{0}", cpuInfo);
            }

            //获取硬盘ID
            String HDid;
            ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
            ManagementObjectCollection moc1 = cimobject1.GetInstances();
            foreach (ManagementObject mo in moc1)
            {
                HDid = (string)mo.Properties["Model"].Value;
                Console.WriteLine("硬盘序列号:{0}", HDid);
            }

            //获取网卡硬件地址
            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc2 = mc.GetInstances();
            foreach (ManagementObject mo in moc2)
            {
                if ((bool)mo["IPEnabled"] == true)
                    Console.WriteLine("网卡地址:{0}", mo["MacAddress"].ToString());
            }

            Console.WriteLine("{0} {1}位 {2}核",
                Environment.OSVersion.VersionString,
                addressWidth,
                Environment.ProcessorCount
            );

//string name = Dns.GetHostName();
//var ips = Dns.GetHostAddresses(name);
GetInfo();


本文由【waitig】发表在等英博客
本文固定链接:c# 获取服务器操作系统信息
欢迎关注本站官方公众号,每日都有干货分享!
等英博客官方公众号
点赞 (0)分享 (0)