Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. // the order is important, if we want to support bitwise OR: IPv4 | IPv6 equals IPv4and6
  2. enum IpVersion
  3. {
  4. None,
  5. IPv4,
  6. IPv6,
  7. IPv4and6
  8. }
  9.  
  10. IpVersion GetConfiguredProtocolVersions(ConnectionProfile profile)
  11. {
  12. var result = IpVersion.None;
  13.  
  14. if (profile != null && profile.NetworkAdapter != null)
  15. {
  16. var hostnames = NetworkInformation
  17. .GetHostNames()
  18. .Where(h => h.IPInformation != null &&
  19. h.IPInformation.NetworkAdapter != null &&
  20. h.IPInformation.NetworkAdapter.NetworkAdapterId == profile.NetworkAdapter.NetworkAdapterId);
  21.  
  22. foreach (var hostname in hostnames)
  23. {
  24. if (hostname.Type == HostNameType.Ipv4)
  25. {
  26. result |= IpVersion.IPv4;
  27. }
  28. else if (hostname.Type == HostNameType.Ipv6)
  29. {
  30. result |= IpVersion.IPv6;
  31. }
  32. }
  33. }
  34.  
  35. return result;
  36. }
  37.  
  38.  
  39. // USAGE: GetConfiguredProtocolVersions(NetworkInformation.GetInternetConnectionProfile());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement