Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


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);

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

.NET 9 és más verziók
Termék Verziók
.NET 6, 7, 8, 9

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<System.Net.IPAddress[]> GetHostAddressesAsync (string hostNameOrAddress, System.Threading.CancellationToken cancellationToken);

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

.NET 9 és más verziók
Termék Verziók
.NET 6, 7, 8, 9

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<System.Net.IPAddress[]> GetHostAddressesAsync (string hostNameOrAddress);

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

.NET 9 és más verziók
Termék Verziók
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1