【新增】 获取学生端本地的IPV4地址

This commit is contained in:
dlaren
2025-09-14 16:24:51 +08:00
parent e594e4d854
commit a78f9db69f

View File

@@ -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;
//}
}