Dns.GetHostEntryAsync Metodo

Definizione

Risolve un nome host o un indirizzo IP in un'istanza di IPHostEntry come un'operazione asincrona.

Overload

GetHostEntryAsync(IPAddress)

Risolve un nome host o un indirizzo IP in un'istanza di IPHostEntry come un'operazione asincrona.

GetHostEntryAsync(String)

Risolve un nome host o un indirizzo IP in un'istanza di IPHostEntry come un'operazione asincrona.

GetHostEntryAsync(String, CancellationToken)

Risolve un nome host o un indirizzo IP in un'istanza di IPHostEntry come un'operazione asincrona.

GetHostEntryAsync(String, AddressFamily, CancellationToken)

Risolve un nome host o un indirizzo IP in un'istanza di IPHostEntry come un'operazione asincrona.

GetHostEntryAsync(IPAddress)

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

Risolve un nome host o un indirizzo IP in un'istanza di IPHostEntry come un'operazione asincrona.

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)

Parametri

address
IPAddress

Indirizzo IP.

Restituisce

Oggetto dell'attività che rappresenta l'operazione asincrona. La proprietà di Result nell'oggetto attività restituisce un'istanza di IPHostEntry che contiene informazioni di indirizzo sull'host specificato in address.

Eccezioni

address è null.

Si è verificato un errore durante la risoluzione del parametro address.

address è un indirizzo IP non valido.

Commenti

Questa operazione non verrà bloccata. L'oggetto restituito Task<TResult> verrà completato dopo la address risoluzione.

Questo metodo esegue una query su un server DNS per gli indirizzi IP e gli alias associati a un indirizzo IP.

Gli indirizzi IPv6 vengono filtrati dai risultati di questo metodo se il computer locale non ha installato IPv6. Di conseguenza, è possibile tornare a un'istanza vuota IPHostEntry se solo IPv6 risultati in cui è disponibile per il address parametro.

La Aliases proprietà dell'istanza IPHostEntry restituita non viene popolata da questo metodo e sarà sempre vuota.

Nota

Questo membro genera informazioni di traccia quando si abilita la traccia di rete nell'applicazione. Per altre informazioni, vedere Traccia di rete in .NET Framework.

Questo metodo archivia nell'attività che restituisce tutte le eccezioni non di utilizzo che la controparte sincrona del metodo può generare. Se un'eccezione viene archiviata nell'attività restituita, tale eccezione verrà generata quando l'attività è attesa. Le eccezioni di utilizzo, ad esempio ArgumentException, vengono comunque generate in modo sincrono. Per le eccezioni archiviate, vedere le eccezioni generate da GetHostEntry(IPAddress).

Si applica a

GetHostEntryAsync(String)

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

Risolve un nome host o un indirizzo IP in un'istanza di IPHostEntry come un'operazione asincrona.

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)

Parametri

hostNameOrAddress
String

Nome dell'host o indirizzo IP da risolvere.

Restituisce

Oggetto dell'attività che rappresenta l'operazione asincrona. La proprietà di Result nell'oggetto attività restituisce un'istanza di IPHostEntry che contiene informazioni di indirizzo sull'host specificato in hostNameOrAddress.

Eccezioni

Il valore del parametro hostNameOrAddress è null.

La lunghezza del parametro hostNameOrAddress supera i 255 caratteri.

Si è verificato un errore nella risoluzione del parametro hostNameOrAddress.

Il parametro hostNameOrAddress è un indirizzo IP non valido.

Commenti

Questa operazione non verrà bloccata. L'oggetto restituito Task<TResult> verrà completato dopo la hostNameOrAddress risoluzione.

Questo metodo esegue una query su un server DNS per l'indirizzo IP associato a un nome host o a un indirizzo IP.

Se una stringa vuota viene passata come hostNameOrAddress argomento, questo metodo restituisce gli indirizzi IPv4 e IPv6 dell'host locale.

Se il nome host non è stato trovato, l'eccezione SocketException viene restituita con un valore pari a 11001 (errore Windows Sockets WSAHOST_NOT_FOUND). Questa eccezione può essere restituita se il server DNS non risponde. Questa eccezione può essere restituita anche se il nome non è un nome host o un alias ufficiale oppure non può essere trovato nei database in cui viene eseguita una query.

L'eccezione ArgumentException viene restituita anche se il hostNameOrAddress parametro contiene Any o IPv6Any.

Questo metodo presuppone che se una stringa letterale IP viene passata nel hostNameOrAddress parametro che l'applicazione vuole restituire un'istanza IPHostEntry con tutte le proprietà impostate. Queste proprietà includono , AddressListAliasese HostName. Di conseguenza, l'implementazione di questo metodo mostra il comportamento seguente quando viene passato un valore letterale stringa IP:

  1. Il metodo tenta di analizzare l'indirizzo. Se il hostNameOrAddress parametro contiene un valore letterale stringa IP legale, la prima fase ha esito positivo.

  2. Viene tentata una ricerca inversa usando l'indirizzo IP del valore letterale stringa IP per ottenere il nome host. Questo risultato viene impostato come HostName proprietà.

  3. Il nome host di questa ricerca inversa viene usato di nuovo per ottenere tutti gli indirizzi IP possibili associati al nome e impostare come AddressList proprietà.

Per un valore letterale stringa IPv4, tutti e tre i passaggi precedenti potrebbero avere esito positivo. Tuttavia, è possibile restituire un record DNS non aggiornato per un indirizzo IPv4 che appartiene effettivamente a un host diverso. Questo può causare l'esito negativo del passaggio 3 e generare un'eccezione (è presente un record PTR DNS per l'indirizzo IPv4, ma nessun record DNS per l'indirizzo IPv4).

Per IPv6, il passaggio 2 precedente potrebbe non riuscire, poiché la maggior parte delle distribuzioni IPv6 non registra il record PTR inverso per un indirizzo IPv6. Questo metodo può quindi restituire il valore letterale IPv6 stringa come nome host completo (FQDN) nella HostName proprietà.

Il GetHostAddresses metodo ha un comportamento diverso rispetto ai valori letterali IP. Se il passaggio 1 precedente ha esito positivo (analizza correttamente come indirizzo IP), tale indirizzo viene restituito immediatamente come risultato. Non esiste alcun tentativo di ricerca inversa.

Gli indirizzi IPv6 vengono filtrati dai risultati di questo metodo se il computer locale non ha installato IPv6. Di conseguenza, è possibile tornare a un'istanza vuota IPHostEntry se solo i risultati IPv6 sono disponibili per il hostNameOrAddressparametro ..

La Aliases proprietà dell'istanza IPHostEntry restituita non viene popolata da questo metodo e sarà sempre vuota.

Questo metodo viene implementato usando le API di risoluzione dei nomi del sistema operativo sottostanti, ad esempio l'API Win32 getaddrinfo in Windows e le API equivalenti in altre piattaforme. Se un host è descritto nel file, verrà restituito l'indirizzo hosts IP o gli indirizzi senza eseguire query sul server DNS.

Nota

Questo membro genera informazioni di traccia quando si abilita la traccia di rete nell'applicazione. Per altre informazioni, vedere Traccia di rete in .NET Framework.

Questo metodo archivia nell'attività che restituisce tutte le eccezioni non di utilizzo che la controparte sincrona del metodo può generare. Se un'eccezione viene archiviata nell'attività restituita, tale eccezione verrà generata quando l'attività è attesa. Le eccezioni di utilizzo, ad esempio ArgumentException, vengono comunque generate in modo sincrono. Per le eccezioni archiviate, vedere le eccezioni generate da GetHostEntry(String).

Si applica a

GetHostEntryAsync(String, CancellationToken)

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

Risolve un nome host o un indirizzo IP in un'istanza di IPHostEntry come un'operazione asincrona.

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)

Parametri

hostNameOrAddress
String

Nome dell'host o indirizzo IP da risolvere.

cancellationToken
CancellationToken

Token di annullamento che può essere usato per segnalare che l'operazione asincrona deve essere annullata.

Restituisce

Oggetto dell'attività che rappresenta l'operazione asincrona. La Result proprietà nell'oggetto attività restituisce un'istanza IPHostEntry contenente le informazioni sull'indirizzo sull'host specificato in hostNameOrAddress.

Eccezioni

Il token di annullamento è stato annullato. Questa eccezione viene archiviata nell'attività restituita.

Commenti

Questo metodo archivia nell'attività che restituisce tutte le eccezioni non di utilizzo che la controparte sincrona del metodo può generare. Se un'eccezione viene archiviata nell'attività restituita, tale eccezione verrà generata quando l'attività è attesa. Le eccezioni di utilizzo, ad esempio ArgumentException, vengono comunque generate in modo sincrono. Per le eccezioni archiviate, vedere le eccezioni generate da GetHostEntry(String).

Si applica a

GetHostEntryAsync(String, AddressFamily, CancellationToken)

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

Risolve un nome host o un indirizzo IP in un'istanza di IPHostEntry come un'operazione asincrona.

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)

Parametri

hostNameOrAddress
String

Nome dell'host o indirizzo IP da risolvere.

family
AddressFamily

Famiglia di indirizzi per cui è necessario recuperare gli INDIRIZZI IP. Se Unspecified, recuperare tutti gli INDIRIZZI IP indipendentemente dalla famiglia di indirizzi.

cancellationToken
CancellationToken

Token di annullamento che può essere usato per segnalare che l'operazione asincrona deve essere annullata.

Restituisce

Oggetto dell'attività che rappresenta l'operazione asincrona. La Result proprietà nell'oggetto attività restituisce un'istanza IPHostEntry che contiene le informazioni sull'indirizzo sull'host specificato in hostNameOrAddress.

Eccezioni

Il token di annullamento è stato annullato. Questa eccezione viene archiviata nell'attività restituita.

Commenti

Questo metodo archivia nell'attività che restituisce tutte le eccezioni non di utilizzo che la controparte sincrona del metodo può generare. Se un'eccezione viene archiviata nell'attività restituita, tale eccezione verrà generata quando l'attività è attesa. Le eccezioni di utilizzo, ad esempio ArgumentException, vengono comunque generate in modo sincrono. Per le eccezioni archiviate, vedere le eccezioni generate da GetHostEntry(String, AddressFamily).

Si applica a