|
|
|
@ -1,14 +1,42 @@
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Management;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.NetworkInformation;
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace Infrastructure.Extensions
|
|
|
|
|
{
|
|
|
|
|
public static class HelperExtensions
|
|
|
|
|
{
|
|
|
|
|
public static string GetCPUNumber(this Helper helper)
|
|
|
|
|
{
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
|
{
|
|
|
|
|
//bash:cat /proc/cpuinfo
|
|
|
|
|
return Regex.Match(File.ReadAllText("/proc/cpuinfo"), @"Serial\s*:\s*([^\s]+)").Groups[1].Value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//cmd:WMic CPU get PRocessorID
|
|
|
|
|
string cpuID = string.Empty;
|
|
|
|
|
var mc = new ManagementClass("win32_processor");
|
|
|
|
|
var moc = mc.GetInstances();
|
|
|
|
|
|
|
|
|
|
foreach (ManagementObject mo in moc)
|
|
|
|
|
{
|
|
|
|
|
if (cpuID == "")
|
|
|
|
|
{
|
|
|
|
|
cpuID = mo.Properties["processorID"].Value.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return cpuID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetMacAddress(this Helper helper)
|
|
|
|
|
{
|
|
|
|
|
var physicalAddress = NetworkInterface
|
|
|
|
|