AdapterInfo.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Net.NetworkInformation;
  2. namespace NetworkTool.Client.Models;
  3. public sealed class AdapterInfo
  4. {
  5. public required string Id { get; set; }
  6. public required string Name { get; set; }
  7. public required string Description { get; set; }
  8. public required string Type { get; set; }
  9. public required bool IsUp { get; set; }
  10. public required bool HasLink { get; set; }
  11. public required int RecommendationScore { get; set; }
  12. public required string RecommendationLabel { get; set; }
  13. public required string RecommendationReason { get; set; }
  14. public string IPv4Address { get; set; } = string.Empty;
  15. public string ProbeStatus { get; set; } = "未探测";
  16. public string ProbeReason { get; set; } = "尚未对 169.254.100.2 进行可达性探测。";
  17. public bool IsReachableToMaintenance { get; set; }
  18. public string DisplayName => $"{RecommendationLabel} | {Name} | {Type} | IPv4: {(string.IsNullOrWhiteSpace(IPv4Address) ? "无" : IPv4Address)} | {ProbeStatus}";
  19. public static AdapterInfo FromNetworkInterface(
  20. NetworkInterface adapter,
  21. string ipv4Address,
  22. int recommendationScore,
  23. string recommendationLabel,
  24. string recommendationReason)
  25. {
  26. return new AdapterInfo
  27. {
  28. Id = adapter.Id,
  29. Name = adapter.Name,
  30. Description = adapter.Description,
  31. Type = adapter.NetworkInterfaceType.ToString(),
  32. IsUp = adapter.OperationalStatus == OperationalStatus.Up,
  33. HasLink = adapter.OperationalStatus == OperationalStatus.Up,
  34. RecommendationScore = recommendationScore,
  35. RecommendationLabel = recommendationLabel,
  36. RecommendationReason = recommendationReason,
  37. IPv4Address = ipv4Address,
  38. };
  39. }
  40. }