|
@@ -18,8 +18,9 @@ namespace IES.ExamServer.Services
|
|
string hostName = $"{Environment.UserName}-{Dns.GetHostName()}";
|
|
string hostName = $"{Environment.UserName}-{Dns.GetHostName()}";
|
|
string os = RuntimeInformation.OSDescription;
|
|
string os = RuntimeInformation.OSDescription;
|
|
//获取当前客户端的服务端口
|
|
//获取当前客户端的服务端口
|
|
-
|
|
|
|
- ServerDevice device = new ServerDevice { name =hostName, os= os,region=region,remote=remote };
|
|
|
|
|
|
+ string currentUserName = Environment.UserName;
|
|
|
|
+
|
|
|
|
+ ServerDevice device = new ServerDevice { name =hostName, userName=currentUserName, os= os,region=region,remote=remote };
|
|
int CpuCoreCount = 0;
|
|
int CpuCoreCount = 0;
|
|
long MenemorySize = 0;
|
|
long MenemorySize = 0;
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
@@ -50,13 +51,50 @@ namespace IES.ExamServer.Services
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ if (Environment.Is64BitOperatingSystem)
|
|
|
|
+ {
|
|
|
|
+ device.bit="64";
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ device.bit="32";
|
|
|
|
+ }
|
|
|
|
+ ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Name, MaxClockSpeed FROM Win32_Processor");
|
|
|
|
+ foreach (ManagementObject mo in searcher.Get())
|
|
|
|
+ {
|
|
|
|
+ string? cpuName = mo["Name"].ToString();
|
|
|
|
+ string? clockSpeed = mo["MaxClockSpeed"].ToString();
|
|
|
|
+ //Console.WriteLine($"CPU 名称: {cpuName}");
|
|
|
|
+ //Console.WriteLine($"CPU 主频: {clockSpeed} MHz");
|
|
|
|
+ device.cpuInfos.Add(new CPUInfo { name = cpuName, hz = clockSpeed });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
{
|
|
{
|
|
//int processorCount = Environment.ProcessorCount;
|
|
//int processorCount = Environment.ProcessorCount;
|
|
// Console.WriteLine("CPU 核心数: " + processorCount);
|
|
// Console.WriteLine("CPU 核心数: " + processorCount);
|
|
- string[] cpu_lines = File.ReadAllLines("/proc/cpuinfo");
|
|
|
|
- CpuCoreCount= cpu_lines.Count(line => line.StartsWith("processor", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
+ try {
|
|
|
|
+ string cpuInfo = File.ReadAllText("/proc/cpuinfo");
|
|
|
|
+ string[] cpu_lines = cpuInfo.Split('\n');
|
|
|
|
+
|
|
|
|
+ CpuCoreCount= cpu_lines.Count(line => line.StartsWith("processor", StringComparison.OrdinalIgnoreCase));
|
|
|
|
+ string? cpuNameLine = cpuInfo.Split('\n').FirstOrDefault(line => line.StartsWith("model name"));
|
|
|
|
+ string? clockSpeedLine = cpuInfo.Split('\n').FirstOrDefault(line => line.StartsWith("cpu MHz"));
|
|
|
|
+ string cpuName = string.Empty;
|
|
|
|
+ string clockSpeed = string.Empty;
|
|
|
|
+ if (cpuNameLine!= null)
|
|
|
|
+ {
|
|
|
|
+ cpuName = cpuNameLine.Split(':').Last().Trim();
|
|
|
|
+ }
|
|
|
|
+ if (clockSpeedLine!= null)
|
|
|
|
+ {
|
|
|
|
+ clockSpeed = clockSpeedLine.Split(':').Last().Trim();
|
|
|
|
+ }
|
|
|
|
+ device.cpuInfos.Add(new CPUInfo { name = cpuName, hz = clockSpeed });
|
|
|
|
+ } catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ }
|
|
string[] mem_lines = File.ReadAllLines("/proc/meminfo");
|
|
string[] mem_lines = File.ReadAllLines("/proc/meminfo");
|
|
var match = mem_lines.FirstOrDefault(line => line.StartsWith("MemTotal:"));
|
|
var match = mem_lines.FirstOrDefault(line => line.StartsWith("MemTotal:"));
|
|
if (match != null)
|
|
if (match != null)
|
|
@@ -70,38 +108,101 @@ namespace IES.ExamServer.Services
|
|
}
|
|
}
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
{
|
|
{
|
|
- using (var process = new Process())
|
|
|
|
|
|
+ try {
|
|
|
|
+ using (var process = new Process())
|
|
|
|
+ {
|
|
|
|
+ process.StartInfo.FileName = "/usr/sbin/sysctl";
|
|
|
|
+ process.StartInfo.Arguments = "-n hw.ncpu";
|
|
|
|
+ process.StartInfo.RedirectStandardOutput = true;
|
|
|
|
+ process.StartInfo.UseShellExecute = false;
|
|
|
|
+ process.Start();
|
|
|
|
+ string output = process.StandardOutput.ReadToEnd().Trim();
|
|
|
|
+ int coreCount;
|
|
|
|
+ if (int.TryParse(output, out coreCount))
|
|
|
|
+ {
|
|
|
|
+ CpuCoreCount= coreCount;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex) { }
|
|
|
|
+ try
|
|
{
|
|
{
|
|
- process.StartInfo.FileName = "/usr/sbin/sysctl";
|
|
|
|
- process.StartInfo.Arguments = "-n hw.ncpu";
|
|
|
|
- process.StartInfo.RedirectStandardOutput = true;
|
|
|
|
- process.StartInfo.UseShellExecute = false;
|
|
|
|
- process.Start();
|
|
|
|
- string output = process.StandardOutput.ReadToEnd().Trim();
|
|
|
|
- int coreCount;
|
|
|
|
- if (int.TryParse(output, out coreCount))
|
|
|
|
|
|
+ using (var process = new Process())
|
|
{
|
|
{
|
|
- CpuCoreCount= coreCount;
|
|
|
|
|
|
+ process.StartInfo.FileName = "/usr/sbin/sysctl";
|
|
|
|
+ process.StartInfo.Arguments = "-n hw.memsize";
|
|
|
|
+ process.StartInfo.RedirectStandardOutput = true;
|
|
|
|
+ process.StartInfo.UseShellExecute = false;
|
|
|
|
+ process.Start();
|
|
|
|
+ string output = process.StandardOutput.ReadToEnd().Trim();
|
|
|
|
+ long memorySize;
|
|
|
|
+ if (long.TryParse(output, out memorySize))
|
|
|
|
+ {
|
|
|
|
+ MenemorySize= memorySize;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- using (var process = new Process())
|
|
|
|
|
|
+ catch (Exception ex) { }
|
|
|
|
+ try
|
|
{
|
|
{
|
|
- process.StartInfo.FileName = "/usr/sbin/sysctl";
|
|
|
|
- process.StartInfo.Arguments = "-n hw.memsize";
|
|
|
|
- process.StartInfo.RedirectStandardOutput = true;
|
|
|
|
- process.StartInfo.UseShellExecute = false;
|
|
|
|
- process.Start();
|
|
|
|
- string output = process.StandardOutput.ReadToEnd().Trim();
|
|
|
|
- long memorySize;
|
|
|
|
- if (long.TryParse(output, out memorySize))
|
|
|
|
|
|
+ using (var process = new Process())
|
|
{
|
|
{
|
|
- MenemorySize= memorySize;
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ process.StartInfo.FileName = "/usr/sbin/sysctl";
|
|
|
|
+ process.StartInfo.Arguments = "-n machdep.cpu.brand_string";
|
|
|
|
+ process.StartInfo.RedirectStandardOutput = true;
|
|
|
|
+ process.StartInfo.UseShellExecute = false;
|
|
|
|
+ process.Start();
|
|
|
|
+ string cpuName = process.StandardOutput.ReadToEnd().Trim();
|
|
|
|
+
|
|
|
|
+ process.StartInfo.FileName = "/usr/sbin/sysctl";
|
|
|
|
+ process.StartInfo.Arguments = "-n hw.cpu.frequency";
|
|
|
|
+ process.StartInfo.RedirectStandardOutput = true;
|
|
|
|
+ process.StartInfo.UseShellExecute = false;
|
|
|
|
+ process.Start();
|
|
|
|
+ string clockSpeed = process.StandardOutput.ReadToEnd().Trim();
|
|
|
|
+ //Console.WriteLine($"CPU 名称: {cpuName}");
|
|
|
|
+ //Console.WriteLine($"CPU 主频: {clockSpeed} Hz");
|
|
|
|
+ device.cpuInfos.Add(new CPUInfo { name = cpuName, hz = clockSpeed });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ Console.WriteLine($"出现错误: {ex.Message}");
|
|
|
|
+ }
|
|
|
|
+ if (Environment.Is64BitOperatingSystem)
|
|
|
|
+ {
|
|
|
|
+ device.bit="64";
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ device.bit="32";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
|
|
|
|
+ {
|
|
|
|
+ device.arch="ARM64";
|
|
}
|
|
}
|
|
|
|
+ else if (RuntimeInformation.ProcessArchitecture == Architecture.Arm)
|
|
|
|
+ {
|
|
|
|
+ device.arch="ARM32";
|
|
|
|
+ }
|
|
|
|
+ else if (RuntimeInformation.ProcessArchitecture == Architecture.X64)
|
|
|
|
|
|
|
|
+ {
|
|
|
|
+ device.arch="X64";
|
|
|
|
+ }
|
|
|
|
+ else if (RuntimeInformation.ProcessArchitecture == Architecture.X86)
|
|
|
|
+ {
|
|
|
|
+ device.arch="X86";
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ device.arch=$"未知({device.arch})";
|
|
|
|
+ }
|
|
//Console.WriteLine("CPU 核心数: " + CpuCoreCount+",RAM 大小:"+MenemorySize);
|
|
//Console.WriteLine("CPU 核心数: " + CpuCoreCount+",RAM 大小:"+MenemorySize);
|
|
-
|
|
|
|
|
|
+
|
|
device.cpu=CpuCoreCount;
|
|
device.cpu=CpuCoreCount;
|
|
device.ram=MenemorySize;
|
|
device.ram=MenemorySize;
|
|
var nics = NetworkInterface.GetAllNetworkInterfaces();
|
|
var nics = NetworkInterface.GetAllNetworkInterfaces();
|
|
@@ -277,6 +378,7 @@ namespace IES.ExamServer.Services
|
|
/// 设备id
|
|
/// 设备id
|
|
/// </summary>
|
|
/// </summary>
|
|
public string? deviceId { get; set; }
|
|
public string? deviceId { get; set; }
|
|
|
|
+ public string? userName { get; set; }
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 机器名
|
|
/// 机器名
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -286,9 +388,19 @@ namespace IES.ExamServer.Services
|
|
/// </summary>
|
|
/// </summary>
|
|
public string? os { get; set; }
|
|
public string? os { get; set; }
|
|
/// <summary>
|
|
/// <summary>
|
|
|
|
+ /// 操作系统位数 64位/32位
|
|
|
|
+ /// </summary>
|
|
|
|
+ public string? bit { get; set; }
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 操作系统指令架构 x86/x64, arm arm64 其他
|
|
|
|
+ /// </summary>
|
|
|
|
+ public string? arch { get; set; }
|
|
|
|
+ /// <summary>
|
|
/// CPU核心数量
|
|
/// CPU核心数量
|
|
/// </summary>
|
|
/// </summary>
|
|
- public int cpu { get; set; }
|
|
|
|
|
|
+ public int cpu { get; set; }
|
|
|
|
+
|
|
|
|
+ public List<CPUInfo> cpuInfos { get; set; } = new List<CPUInfo>();
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 内存大小
|
|
/// 内存大小
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -310,6 +422,11 @@ namespace IES.ExamServer.Services
|
|
/// </summary>
|
|
/// </summary>
|
|
public List<Network> networks { get; set; } = new List<Network>();
|
|
public List<Network> networks { get; set; } = new List<Network>();
|
|
}
|
|
}
|
|
|
|
+ public class CPUInfo
|
|
|
|
+ {
|
|
|
|
+ public string? name { get; set; }
|
|
|
|
+ public string? hz { get; set; }
|
|
|
|
+ }
|
|
public class Network
|
|
public class Network
|
|
{
|
|
{
|
|
public string? name { get; set; }
|
|
public string? name { get; set; }
|