feat: 配置板子网络时,更新动态mac
This commit is contained in:
parent
bafd06162c
commit
2adeca3b99
|
@ -14,6 +14,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ArpLookup" Version="2.0.3" />
|
||||
<PackageReference Include="DotNext" Version="5.23.0" />
|
||||
<PackageReference Include="DotNext.Threading" Version="5.23.0" />
|
||||
<PackageReference Include="Honoo.IO.Hashing.Crc" Version="1.3.3" />
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
using System.Diagnostics;
|
||||
using System.Net.NetworkInformation;
|
||||
using ArpLookup;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
/// <summary>
|
||||
/// ARP 记录管理静态类(跨平台支持)
|
||||
/// </summary>
|
||||
public static class Arp
|
||||
public static class ArpClient
|
||||
{
|
||||
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
|
@ -44,20 +47,28 @@ public static class Arp
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过 Ping 动态更新指定 IP 的 ARP 记录
|
||||
/// 动态更新指定 IP 的 ARP 记录
|
||||
/// </summary>
|
||||
/// <param name="ipAddress">要更新的 IP 地址</param>
|
||||
/// <returns>是否成功发送 Ping</returns>
|
||||
public static async Task<bool> UpdateArpEntryByPingAsync(string ipAddress)
|
||||
public static async Task<bool> UpdateArpEntryAsync(string ipAddress)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(ipAddress))
|
||||
throw new ArgumentException("IP 地址不能为空", nameof(ipAddress));
|
||||
|
||||
try
|
||||
{
|
||||
using var ping = new System.Net.NetworkInformation.Ping();
|
||||
var reply = await ping.SendPingAsync(ipAddress, 100);
|
||||
return reply.Status == System.Net.NetworkInformation.IPStatus.Success;
|
||||
var ret = await ArpClient.DeleteArpEntryAsync(ipAddress);
|
||||
if (!ret)
|
||||
{
|
||||
logger.Error($"删除 ARP 记录失败: {ipAddress}");
|
||||
}
|
||||
|
||||
PhysicalAddress? mac = await Arp.LookupAsync(IPAddress.Parse(ipAddress));
|
||||
if (mac == null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
|
@ -278,7 +278,7 @@ public class DataController : ControllerBase
|
|||
return NotFound("没有可用的实验板");
|
||||
|
||||
var boardInfo = boardOpt.Value;
|
||||
if (!(await Arp.CheckOrAddAsync(boardInfo.IpAddr, boardInfo.MacAddr, GetLocalIPAddress().ToString())))
|
||||
if (!(await ArpClient.CheckOrAddAsync(boardInfo.IpAddr, boardInfo.MacAddr, GetLocalIPAddress().ToString())))
|
||||
{
|
||||
logger.Error($"无法配置ARP,实验板可能会无法连接");
|
||||
}
|
||||
|
@ -346,7 +346,7 @@ public class DataController : ControllerBase
|
|||
return NotFound("未找到对应的实验板");
|
||||
|
||||
var boardInfo = ret.Value.Value;
|
||||
if (!(await Arp.CheckOrAddAsync(boardInfo.IpAddr, boardInfo.MacAddr, GetLocalIPAddress().ToString())))
|
||||
if (!(await ArpClient.CheckOrAddAsync(boardInfo.IpAddr, boardInfo.MacAddr, GetLocalIPAddress().ToString())))
|
||||
{
|
||||
logger.Error($"无法配置ARP,实验板可能会无法连接");
|
||||
}
|
||||
|
@ -490,4 +490,3 @@ public class DataController : ControllerBase
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -380,7 +380,7 @@ public class DebuggerController : ControllerBase
|
|||
}
|
||||
|
||||
var rawData = dataResult.Value;
|
||||
logger.Debug($"rawData: {BitConverter.ToString(rawData)}");
|
||||
// logger.Debug($"rawData: {BitConverter.ToString(rawData)}");
|
||||
int depth = (int)config.captureDepth;
|
||||
int portDataLen = 4 * depth;
|
||||
int portNum = (int)config.totalPortNum;
|
||||
|
@ -413,8 +413,7 @@ public class DebuggerController : ControllerBase
|
|||
}
|
||||
var channelBytes = new byte[4 * depth];
|
||||
Buffer.BlockCopy(channelUintArr, 0, channelBytes, 0, channelBytes.Length);
|
||||
channelBytes = Common.Number.ReverseBytes(channelBytes, 4).Value;
|
||||
logger.Debug($"{channel.name} HexData: {BitConverter.ToString(channelBytes)}");
|
||||
// logger.Debug($"{channel.name} HexData: {BitConverter.ToString(channelBytes)}");
|
||||
var base64 = Convert.ToBase64String(channelBytes);
|
||||
channelDataList.Add(new ChannelCaptureData { name = channel.name, data = base64 });
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ public class NetConfigController : ControllerBase
|
|||
// 固定的实验板IP,端口,MAC地址
|
||||
private const string BOARD_IP = "169.254.109.0";
|
||||
private const int BOARD_PORT = 1234;
|
||||
private const string BOARD_MAC = "12:34:56:78:9a:bc";
|
||||
|
||||
// 本机网络信息
|
||||
private readonly IPAddress _localIP;
|
||||
|
@ -130,7 +129,7 @@ public class NetConfigController : ControllerBase
|
|||
{
|
||||
try
|
||||
{
|
||||
return await Arp.CheckOrAddAsync(BOARD_IP, BOARD_MAC, _localInterface);
|
||||
return await ArpClient.UpdateArpEntryAsync(BOARD_IP);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@ public static class MsgBus
|
|||
/// <returns>无</returns>
|
||||
public async static void Init()
|
||||
{
|
||||
if (!Arp.IsAdministrator())
|
||||
if (!ArpClient.IsAdministrator())
|
||||
{
|
||||
logger.Error($"非管理员运行,ARP无法更新,请用管理员权限运行");
|
||||
// throw new Exception($"非管理员运行,ARP无法更新,请用管理员权限运行");
|
||||
|
|
|
@ -479,10 +479,10 @@ async function startCapture() {
|
|||
const arr = [];
|
||||
for (let i = 0; i < bin.length; i += 4) {
|
||||
arr.push(
|
||||
(bin.charCodeAt(i) << 24) |
|
||||
(bin.charCodeAt(i + 1) << 16) |
|
||||
(bin.charCodeAt(i + 2) << 8) |
|
||||
bin.charCodeAt(i + 3),
|
||||
bin.charCodeAt(i) |
|
||||
(bin.charCodeAt(i + 1) << 8) |
|
||||
(bin.charCodeAt(i + 2) << 16) |
|
||||
(bin.charCodeAt(i + 3) << 24),
|
||||
);
|
||||
}
|
||||
// 截取采样深度
|
||||
|
|
Loading…
Reference in New Issue