RemoteInterfaceInfo.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Text.Json.Serialization;
  4. namespace NetworkTool.Client.Models;
  5. public sealed class RemoteInterfaceAddress
  6. {
  7. [JsonPropertyName("address")]
  8. public string Address { get; init; } = string.Empty;
  9. [JsonPropertyName("prefix")]
  10. public int Prefix { get; init; }
  11. [JsonPropertyName("source")]
  12. public string Source { get; init; } = string.Empty;
  13. }
  14. public sealed class RemoteInterfaceInfo
  15. {
  16. [JsonPropertyName("name")]
  17. public string Name { get; init; } = string.Empty;
  18. [JsonPropertyName("system_name")]
  19. public string SystemName { get; init; } = string.Empty;
  20. [JsonPropertyName("role")]
  21. public string Role { get; init; } = string.Empty;
  22. [JsonPropertyName("link_up")]
  23. public bool LinkUp { get; init; }
  24. [JsonPropertyName("is_management_interface")]
  25. public bool IsManagementInterface { get; init; }
  26. [JsonPropertyName("is_suggested_target")]
  27. public bool IsSuggestedTarget { get; init; }
  28. [JsonPropertyName("mac")]
  29. public string Mac { get; init; } = string.Empty;
  30. [JsonPropertyName("gateway")]
  31. public string Gateway { get; init; } = string.Empty;
  32. [JsonPropertyName("dns")]
  33. public IReadOnlyList<string> Dns { get; init; } = [];
  34. [JsonPropertyName("ipv4")]
  35. public IReadOnlyList<RemoteInterfaceAddress> IPv4 { get; init; } = [];
  36. public string IPv4Summary => IPv4.Count == 0
  37. ? "无"
  38. : string.Join("; ", IPv4.Select(item => $"{item.Address}/{item.Prefix}"));
  39. public string StatusSummary => IsManagementInterface
  40. ? $"管理接口 / {(LinkUp ? "已连接" : "未连接")}"
  41. : LinkUp ? "已连接" : "未连接";
  42. public string DisplayName => $"{SystemName} / {StatusSummary}";
  43. }
  44. public sealed class RemoteInterfacesInfo
  45. {
  46. [JsonPropertyName("management_interface")]
  47. public string ManagementInterface { get; init; } = string.Empty;
  48. [JsonPropertyName("suggested_target_interface")]
  49. public string SuggestedTargetInterface { get; init; } = string.Empty;
  50. [JsonPropertyName("requires_target_selection")]
  51. public bool RequiresTargetSelection { get; init; }
  52. [JsonPropertyName("interfaces")]
  53. public IReadOnlyList<RemoteInterfaceInfo> Interfaces { get; init; } = [];
  54. }