You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
using System;
|
|
using System.IO;
|
|
using System.Management;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace IdTest
|
|
{
|
|
internal class Program
|
|
{
|
|
private static void Main(string[] args)
|
|
{
|
|
Console.WriteLine(GetCPUNumber());
|
|
}
|
|
|
|
public static string GetCPUNumber()
|
|
{
|
|
var result = string.Empty;
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
{
|
|
result = Regex.Match(File.ReadAllText("/proc/cpuinfo"), @"Serial\s*:\s*([^\s]+)").Groups[1].Value;
|
|
}
|
|
else
|
|
{
|
|
var mc = new ManagementClass("win32_processor");
|
|
var moc = mc.GetInstances();
|
|
|
|
foreach (ManagementObject mo in moc)
|
|
{
|
|
if (result == "")
|
|
{
|
|
result = mo.Properties["processorID"].Value.ToString();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return result.ToLower();
|
|
}
|
|
}
|
|
} |