I'm coding an application that has to get the network adapters configuration on a Windows 7 machine just like it's done in the Windows network adapters configuration panel:
So far I can get pretty much all the information I need from NetworkInterface.GetAllNetworkInterfaces()
EXCEPT the subnet prefix length.
I'm aware that it can be retrieved from the C++ struc PMIB_UNICASTIPADDRESS_TABLE
via OnLinkPrefixLength
but I'm trying to stay in .net.
I also took a look at the Win32_NetworkAdapterConfiguration
WMI class but it only seems to return the IP v4 subnet mask.
I also know that some information (not the prefix length, as far as I know) are in the registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\TCPIP6\Parameters\Interfaces\{CLSID}
I also used SysInternals ProcessMon to try to get anything usefull when saving the network adapter settings but found nothing...
So, is there any clean .NET way to get this value? (getting it from the registry wouldn't be a problem)
EDIT: Gateways
This doesn't concern the actual question, but for those who need to retrieve the entire network adapter IPv6 configuration, the IPInterfaceProperties.GatewayAdresses
property only supports the IPv4 gateways. As mentionned in the answer comments below, the only way to get the entire info until .NET framework 4.5 is to call WMI.