Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement