侧边栏壁纸
博主头像
小医仙博主等级

风一程雨一程,身向榆关那畔行。

  • 累计撰写 39 篇文章
  • 累计创建 16 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

.Net获取本机网卡

小医仙
2023-06-13 / 0 评论 / 0 点赞 / 470 阅读 / 129 字
 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

评论区