From a78f9db69fdc129da585366417ddbbf924996349 Mon Sep 17 00:00:00 2001 From: dlaren Date: Sun, 14 Sep 2025 16:24:51 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=20?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=AD=A6=E7=94=9F=E7=AB=AF=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E7=9A=84IPV4=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Applications/Program.cs | 51 ++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/Applications/Program.cs b/Applications/Program.cs index a349188..9dacd9d 100644 --- a/Applications/Program.cs +++ b/Applications/Program.cs @@ -122,8 +122,6 @@ class Program throw new Exception($"压缩失败: {ex.Message}"); } } - - // 下载文件方法 if (action == "/downloadfiles") { @@ -170,6 +168,15 @@ class Program Console.WriteLine($"操作失败: {ex.Message}"); } } + // 获取学生端本地的IPV4地址 + if (action == "/getipv4address") { + Console.WriteLine("获取IPV4"); + responseMessage = Dns.GetHostEntry(Dns.GetHostName()) + .AddressList + .FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork) + ?.ToString() ?? "未找到IPv4地址"; + } + // 打开本地判分的JAVA环境 if (action == "/openjudgement") { string relativePath = ""; @@ -442,6 +449,7 @@ class Program responseMessage = "Error: " + ex.Message; } } + // 停止软件 else if (action == "/stop") { if (!string.IsNullOrEmpty(fileToOpen)) @@ -469,6 +477,7 @@ class Program responseMessage = "Missing 'file' parameter."; } } + // 检测学生端环境 else if (action == "/check") { string apiUrl = "http://" + ip + ":48080/admin-api/exam/app/getAppCheckList/" + taskId; // ← 替换成你的接口地址 @@ -1000,25 +1009,25 @@ class Program return null; // 没找到 } // 获取进程命令行,需要添加 System.Management 引用 - public static string GetCommandLine(Process process) - { - try - { - using (var searcher = new System.Management.ManagementObjectSearcher( - "SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + process.Id)) - { - foreach (var obj in searcher.Get()) - { - return obj["CommandLine"]?.ToString(); - } - } - } - catch - { - return null; - } - return null; - } + //public static string GetCommandLine(Process process) + //{ + // try + // { + // using (var searcher = new System.Management.ManagementObjectSearcher( + // "SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + process.Id)) + // { + // foreach (var obj in searcher.Get()) + // { + // return obj["CommandLine"]?.ToString(); + // } + // } + // } + // catch + // { + // return null; + // } + // return null; + //} }