.Net获取本机网卡
2023-11-15
 public static void Main()
        {
            var networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
            foreach (var networkInterface in networkInterfaces)
            {
                Console.WriteLine($"Name: {networkInterface.Name}");
                Console.WriteLine($"Description: {networkInterface.Description}");
                Console.WriteLine($"Status: {networkInterface.OperationalStatus}");
                Console.WriteLine($"MAC Address: {networkInterface.GetPhysicalAddress()}");
                Console.WriteLine($"IPv4 Addresses:");
                foreach (var addressInfo in networkInterface.GetIPProperties().UnicastAddresses)
                {
                    if (addressInfo.Address.AddressFamily == AddressFamily.InterNetwork)
                    {
                        Console.WriteLine($"  {addressInfo.Address}");
                    }
                }

                Console.WriteLine($"IPv6 Addresses:");
                foreach (var addressInfo in networkInterface.GetIPProperties().UnicastAddresses)
                {
                    if (addressInfo.Address.AddressFamily == AddressFamily.InterNetworkV6)
                    {
                        Console.WriteLine($"  {addressInfo.Address}");
                    }
                }

                Console.WriteLine();
            }
        }

AppContext.SetSwitch(“System.Net.DisableIPv6”, true);
参考链接:https://blog.csdn.net/MINGSON666/article/details/123537737
https://github.com/dotnet/runtime/pull/55012
https://github.com/dotnet/runtime/commit/067aa165d97372f3e281786801d014fccea8b12c