Edit

Share via


Dns.GetHostAddressesAsync Method

Definition

Overloads

GetHostAddressesAsync(String, AddressFamily, CancellationToken)

Returns the Internet Protocol (IP) addresses for the specified host as an asynchronous operation.

GetHostAddressesAsync(String, CancellationToken)

Returns the Internet Protocol (IP) addresses for the specified host as an asynchronous operation.

GetHostAddressesAsync(String)

Returns the Internet Protocol (IP) addresses for the specified host as an asynchronous operation.

GetHostAddressesAsync(String, AddressFamily, CancellationToken)

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

Returns the Internet Protocol (IP) addresses for the specified host as an asynchronous operation.

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

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 array of type IPAddress that holds the IP addresses for the host that is specified by the hostNameOrAddress parameter.

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 GetHostAddresses(String, AddressFamily).

Applies to

GetHostAddressesAsync(String, CancellationToken)

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

Returns the Internet Protocol (IP) addresses for the specified host as an asynchronous operation.

public:
 static System::Threading::Tasks::Task<cli::array <System::Net::IPAddress ^> ^> ^ GetHostAddressesAsync(System::String ^ hostNameOrAddress, System::Threading::CancellationToken cancellationToken);
public static System.Threading.Tasks.Task<System.Net.IPAddress[]> GetHostAddressesAsync (string hostNameOrAddress, System.Threading.CancellationToken cancellationToken);
static member GetHostAddressesAsync : string * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Net.IPAddress[]>
Public Shared Function GetHostAddressesAsync (hostNameOrAddress As String, cancellationToken As CancellationToken) As Task(Of IPAddress())

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 array of type IPAddress that holds the IP addresses for the host that is specified by the hostNameOrAddress parameter.

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 GetHostAddresses(String).

Applies to

GetHostAddressesAsync(String)

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

Returns the Internet Protocol (IP) addresses for the specified host as an asynchronous operation.

public:
 static System::Threading::Tasks::Task<cli::array <System::Net::IPAddress ^> ^> ^ GetHostAddressesAsync(System::String ^ hostNameOrAddress);
public static System.Threading.Tasks.Task<System.Net.IPAddress[]> GetHostAddressesAsync (string hostNameOrAddress);
static member GetHostAddressesAsync : string -> System.Threading.Tasks.Task<System.Net.IPAddress[]>
Public Shared Function GetHostAddressesAsync (hostNameOrAddress As String) As Task(Of IPAddress())

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 array of type IPAddress that holds the IP addresses for the host that is specified by the hostNameOrAddress parameter.

Exceptions

hostNameOrAddress is null.

The length of hostNameOrAddress is greater than 255 characters.

An error is encountered when resolving hostNameOrAddress.

hostNameOrAddress 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 addresses associated with a host name. If hostNameOrAddress is an IP address, this address is returned without querying the DNS server.

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 GetHostAddresses(String).

Applies to