Checking if IPv6 is enabled on Windows 7 using C#

前端 未结 3 833
梦谈多话
梦谈多话 2021-01-19 19:06

I am trying to write a program using C# to act as a multipurpose tool for my company. One of the things we would like in this tool is to determine if IPv6 is enabled/binded

3条回答
  •  星月不相逢
    2021-01-19 19:10

    You can query for exactly what you asked for (if IPv6 is enabled or disabled for a specific network adapter) with the following code using the System.Net.NetworkInformation namespace:

    using System.Net.NetworkInformation;
    
    // ...
    
    NetworkInterface[] allInterfaces = NetworkInterface.GetAllNetworkInterfaces();
    NetworkInterface firstInterface = allInterfaces[0];
    bool interfaceSupportsIPv6 = firstInterface.Supports(NetworkInterfaceComponent.IPv6);
    

    Documentation on MSDN: Link

提交回复
热议问题