Skip to content

Instantly share code, notes, and snippets.

@wojciech-kulik
Last active November 26, 2015 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wojciech-kulik/8433d44c79c234277a5a to your computer and use it in GitHub Desktop.
Save wojciech-kulik/8433d44c79c234277a5a to your computer and use it in GitHub Desktop.
// the order is important, if we want to support bitwise OR: IPv4 | IPv6 equals IPv4and6
enum IpVersion
{
None,
IPv4,
IPv6,
IPv4and6
}
IpVersion GetConfiguredProtocolVersions(ConnectionProfile profile)
{
var result = IpVersion.None;
if (profile != null && profile.NetworkAdapter != null)
{
var hostnames = NetworkInformation.GetHostNames()
.Where(h => h.IPInformation != null &&
h.IPInformation.NetworkAdapter != null &&
h.IPInformation.NetworkAdapter.NetworkAdapterId == profile.NetworkAdapter.NetworkAdapterId);
foreach (var hostname in hostnames)
{
if (hostname.Type == HostNameType.Ipv4)
{
result |= IpVersion.IPv4;
}
else if (hostname.Type == HostNameType.Ipv6)
{
result |= IpVersion.IPv6;
}
}
}
return result;
}
// USAGE: GetConfiguredProtocolVersions(NetworkInformation.GetInternetConnectionProfile());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment