DnsAbstraction.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Net;
  2. namespace Renci.SshNet.Abstractions
  3. {
  4. internal static class DnsAbstraction
  5. {
  6. /// <summary>
  7. /// Returns the Internet Protocol (IP) addresses for the specified host.
  8. /// </summary>
  9. /// <param name="hostNameOrAddress">The host name or IP address to resolve</param>
  10. /// <returns>
  11. /// An array of type <see cref="IPAddress"/> that holds the IP addresses for the host that
  12. /// is specified by the <paramref name="hostNameOrAddress"/> parameter.
  13. /// </returns>
  14. public static IPAddress[] GetHostAddresses(string hostNameOrAddress)
  15. {
  16. #if FEATURE_DNS_ASYNC
  17. return Dns.GetHostAddressesAsync(hostNameOrAddress).Result;
  18. #else
  19. return Dns.GetHostAddresses(hostNameOrAddress);
  20. #endif
  21. }
  22. /// <summary>
  23. /// Resolves a host name or IP address to an <see cref="IPHostEntry"/> instance.
  24. /// </summary>
  25. /// <param name="hostNameOrAddress">The host name or IP address to resolve.</param>
  26. /// <returns>
  27. /// An <see cref="IPHostEntry"/> instance that contains address information about the host
  28. /// specified in <paramref name="hostNameOrAddress"/>.
  29. /// </returns>
  30. public static IPHostEntry GetHostEntry(string hostNameOrAddress)
  31. {
  32. #if FEATURE_DNS_ASYNC
  33. return Dns.GetHostEntryAsync(hostNameOrAddress).Result;
  34. #else
  35. return Dns.GetHostEntry(hostNameOrAddress);
  36. #endif
  37. }
  38. }
  39. }