| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using System.Net.NetworkInformation;
- namespace NetTool.Client.Models;
- public sealed class AdapterInfo
- {
- public required string Id { get; set; }
- public required string Name { get; set; }
- public required string Description { get; set; }
- public required string Type { get; set; }
- public required bool IsUp { get; set; }
- public required bool HasLink { get; set; }
- public required int RecommendationScore { get; set; }
- public required string RecommendationLabel { get; set; }
- public required string RecommendationReason { get; set; }
- public string IPv4Address { get; set; } = string.Empty;
- public string IPv4Display => $"IPv4: {(string.IsNullOrWhiteSpace(IPv4Address) ? "无" : IPv4Address)}";
- public string DisplayName => $"{Name} | {IPv4Display}";
- public static AdapterInfo FromNetworkInterface(
- NetworkInterface adapter,
- string ipv4Address,
- int recommendationScore,
- string recommendationLabel,
- string recommendationReason)
- {
- return new AdapterInfo
- {
- Id = adapter.Id,
- Name = adapter.Name,
- Description = adapter.Description,
- Type = adapter.NetworkInterfaceType.ToString(),
- IsUp = adapter.OperationalStatus == OperationalStatus.Up,
- HasLink = adapter.OperationalStatus == OperationalStatus.Up,
- RecommendationScore = recommendationScore,
- RecommendationLabel = recommendationLabel,
- RecommendationReason = recommendationReason,
- IPv4Address = ipv4Address,
- };
- }
- }
|