Last active
November 26, 2015 17:46
-
-
Save wojciech-kulik/8433d44c79c234277a5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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