Redigera

Dela via


Dns.GetHostEntryAsync Method

Definition

Resolves a host name or IP address to an IPHostEntry instance as an asynchronous operation.

Overloads

GetHostEntryAsync(IPAddress)

Resolves an IP address to an IPHostEntry instance as an asynchronous operation.

GetHostEntryAsync(String)

Resolves a host name or IP address to an IPHostEntry instance as an asynchronous operation.

GetHostEntryAsync(String, CancellationToken)

Resolves a host name or IP address to an IPHostEntry instance as an asynchronous operation.

GetHostEntryAsync(String, AddressFamily, CancellationToken)

Resolves a host name or IP address to an IPHostEntry instance as an asynchronous operation.

GetHostEntryAsync(IPAddress)

Source:
Dns.cs
Source:
Dns.cs
Source:
Dns.cs

Resolves an IP address to an IPHostEntry instance as an asynchronous operation.

public:
 static System::Threading::Tasks::Task<System::Net::IPHostEntry ^> ^ GetHostEntryAsync(System::Net::IPAddress ^ address);
public static System.Threading.Tasks.Task<System.Net.IPHostEntry> GetHostEntryAsync (System.Net.IPAddress address);
static member GetHostEntryAsync : System.Net.IPAddress -> System.Threading.Tasks.Task<System.Net.IPHostEntry>
Public Shared Function GetHostEntryAsync (address As IPAddress) As Task(Of IPHostEntry)

Parameters

address
IPAddress

An IP address.

Returns

The task object representing the asynchronous operation. The Result property on the task object returns an IPHostEntry instance that contains address information about the host specified in address.

Exceptions

address is null.

An error is encountered when resolving address.

address is an invalid IP address.

Remarks

This operation will not block. The returned Task<TResult> object will complete after the address has been resolved.

This method queries a DNS server for the IP addresses and aliases associated with an IP address.

IPv6 addresses are filtered from the results of this method if the local computer does not have IPv6 installed. As a result, it is possible to get back an empty IPHostEntry instance if only IPv6 results where available for the address parameter.

The Aliases property of the IPHostEntry instance returned is not populated by this method and will always be empty.

Note

This member emits trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by GetHostEntry(IPAddress).

Applies to

GetHostEntryAsync(String)

Source:
Dns.cs
Source:
Dns.cs
Source:
Dns.cs

Resolves a host name or IP address to an IPHostEntry instance as an asynchronous operation.

public:
 static System::Threading::Tasks::Task<System::Net::IPHostEntry ^> ^ GetHostEntryAsync(System::String ^ hostNameOrAddress);
public static System.Threading.Tasks.Task<System.Net.IPHostEntry> GetHostEntryAsync (string hostNameOrAddress);
static member GetHostEntryAsync : string -> System.Threading.Tasks.Task<System.Net.IPHostEntry>
Public Shared Function GetHostEntryAsync (hostNameOrAddress As String) As Task(Of IPHostEntry)

Parameters

hostNameOrAddress
String

The host name or IP address to resolve.

Returns

The task object representing the asynchronous operation. The Result property on the task object returns an IPHostEntry instance that contains address information about the host specified in hostNameOrAddress.

Exceptions

The hostNameOrAddress parameter is null.

The length of hostNameOrAddress parameter is greater than 255 characters.

An error was encountered when resolving the hostNameOrAddress parameter.

The hostNameOrAddress parameter is an invalid IP address.

Remarks

This operation will not block. The returned Task<TResult> object will complete after the hostNameOrAddress has been resolved.

This method queries a DNS server for the IP address that is associated with a host name or IP address.

If an empty string is passed as the hostNameOrAddress argument, then this method returns the IPv4 and IPv6 addresses of the local host.

If the host name could not be found, the SocketException exception is returned with a value of 11001 (Windows Sockets error WSAHOST_NOT_FOUND). This exception can be returned if the DNS server does not respond. This exception can also be returned if the name is not an official host name or alias, or it cannot be found in the database(s) being queried.

The ArgumentException exception is also returned if the hostNameOrAddress parameter contains Any or IPv6Any.

This method assumes that if an IP literal string is passed in the hostNameOrAddress parameter that the application wants an IPHostEntry instance returned with all of the properties set. These properties include the AddressList, Aliases, and HostName. As a result, the implementation of this method exhibits the following behavior when an IP string literal is passed:

  1. The method tries to parse the address. If the hostNameOrAddress parameter contains a legal IP string literal, then the first phase succeeds.

  2. A reverse lookup using the IP address of the IP string literal is attempted to obtain the host name. This result is set as the HostName property.

  3. The host name from this reverse lookup is used again to obtain all the possible IP addresses associated with the name and set as the AddressList property.

For an IPv4 string literal, all three steps above may succeed. But it is possible for a stale DNS record for an IPv4 address that actually belongs to a different host to be returned. This may cause step #3 to fail and throw an exception (there is a DNS PTR record for the IPv4 address, but no DNS A record for the IPv4 address).

For IPv6, step #2 above may fail, since most IPv6 deployments do not register the reverse (PTR) record for an IPv6 address. So this method may return the string IPv6 literal as the fully-qualified domain (FQDN) host name in the HostName property.

The GetHostAddresses method has different behavior with respect to IP literals. If step #1 above succeeds (it successfully parses as an IP address), that address is immediately returned as the result. There is no attempt at a reverse lookup.

IPv6 addresses are filtered from the results of this method if the local computer does not have IPv6 installed. As a result, it is possible to get back an empty IPHostEntry instance if only IPv6 results where available for the hostNameOrAddress.parameter.

The Aliases property of the IPHostEntry instance returned is not populated by this method and will always be empty.

This method is implemented using the underlying operating system's name resolution APIs (such as the Win32 API getaddrinfo on Windows, and equivalent APIs on other platforms). If a host is described in the hosts file, the IP address or addresses there will be returned without querying the DNS server.

Note

This member emits trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by GetHostEntry(String).

Applies to

GetHostEntryAsync(String, CancellationToken)

Source:
Dns.cs
Source:
Dns.cs
Source:
Dns.cs

Resolves a host name or IP address to an IPHostEntry instance as an asynchronous operation.

public:
 static System::Threading::Tasks::Task<System::Net::IPHostEntry ^> ^ GetHostEntryAsync(System::String ^ hostNameOrAddress, System::Threading::CancellationToken cancellationToken);
public static System.Threading.Tasks.Task<System.Net.IPHostEntry> GetHostEntryAsync (string hostNameOrAddress, System.Threading.CancellationToken cancellationToken);
static member GetHostEntryAsync : string * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Net.IPHostEntry>
Public Shared Function GetHostEntryAsync (hostNameOrAddress As String, cancellationToken As CancellationToken) As Task(Of IPHostEntry)

Parameters

hostNameOrAddress
String

The host name or IP address to resolve.

cancellationToken
CancellationToken

A cancellation token that can be used to signal the asynchronous operation should be canceled.

Returns

The task object representing the asynchronous operation. The Result property on the task object returns an IPHostEntry instance that contains the address information about the host specified in hostNameOrAddress.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by GetHostEntry(String).

Applies to

GetHostEntryAsync(String, AddressFamily, CancellationToken)

Source:
Dns.cs
Source:
Dns.cs
Source:
Dns.cs

Resolves a host name or IP address to an IPHostEntry instance as an asynchronous operation.

public static System.Threading.Tasks.Task<System.Net.IPHostEntry> GetHostEntryAsync (string hostNameOrAddress, System.Net.Sockets.AddressFamily family, System.Threading.CancellationToken cancellationToken = default);
static member GetHostEntryAsync : string * System.Net.Sockets.AddressFamily * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Net.IPHostEntry>
Public Shared Function GetHostEntryAsync (hostNameOrAddress As String, family As AddressFamily, Optional cancellationToken As CancellationToken = Nothing) As Task(Of IPHostEntry)

Parameters

hostNameOrAddress
String

The host name or IP address to resolve.

family
AddressFamily

The address family for which IPs should be retrieved. If Unspecified, retrieve all IPs regardless of address family.

cancellationToken
CancellationToken

A cancellation token that can be used to signal the asynchronous operation should be canceled.

Returns

The task object representing the asynchronous operation. The Result property on the task object returns an IPHostEntry instance that contains the address information about the host specified in hostNameOrAddress.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by GetHostEntry(String, AddressFamily).

Applies to