Dns.BeginGetHostEntry Dns.BeginGetHostEntry Dns.BeginGetHostEntry Dns.BeginGetHostEntry Method

定義

ホスト名または IP アドレスを非同期的に IPHostEntry インスタンスに解決します。Asynchronously resolves a host name or IP address to an IPHostEntry instance.

オーバーロード

BeginGetHostEntry(IPAddress, AsyncCallback, Object) BeginGetHostEntry(IPAddress, AsyncCallback, Object) BeginGetHostEntry(IPAddress, AsyncCallback, Object) BeginGetHostEntry(IPAddress, AsyncCallback, Object)

IP アドレスを非同期的に IPHostEntry インスタンスに解決します。Asynchronously resolves an IP address to an IPHostEntry instance.

BeginGetHostEntry(String, AsyncCallback, Object) BeginGetHostEntry(String, AsyncCallback, Object) BeginGetHostEntry(String, AsyncCallback, Object) BeginGetHostEntry(String, AsyncCallback, Object)

ホスト名または IP アドレスを非同期的に IPHostEntry インスタンスに解決します。Asynchronously resolves a host name or IP address to an IPHostEntry instance.

BeginGetHostEntry(IPAddress, AsyncCallback, Object) BeginGetHostEntry(IPAddress, AsyncCallback, Object) BeginGetHostEntry(IPAddress, AsyncCallback, Object) BeginGetHostEntry(IPAddress, AsyncCallback, Object)

IP アドレスを非同期的に IPHostEntry インスタンスに解決します。Asynchronously resolves an IP address to an IPHostEntry instance.

public:
 static IAsyncResult ^ BeginGetHostEntry(System::Net::IPAddress ^ address, AsyncCallback ^ requestCallback, System::Object ^ stateObject);
public static IAsyncResult BeginGetHostEntry (System.Net.IPAddress address, AsyncCallback requestCallback, object stateObject);
static member BeginGetHostEntry : System.Net.IPAddress * AsyncCallback * obj -> IAsyncResult
Public Shared Function BeginGetHostEntry (address As IPAddress, requestCallback As AsyncCallback, stateObject As Object) As IAsyncResult

パラメーター

address
IPAddress IPAddress IPAddress IPAddress

解決する IP アドレス。The IP address to resolve.

requestCallback
AsyncCallback AsyncCallback AsyncCallback AsyncCallback

操作の完了時に呼び出すメソッドを参照する AsyncCallback デリゲート。An AsyncCallback delegate that references the method to invoke when the operation is complete.

stateObject
Object Object Object Object

操作に関する情報を格納するユーザー定義のオブジェクト。A user-defined object that contains information about the operation. このオブジェクトは、操作の完了時に requestCallback デリゲートに渡されます。This object is passed to the requestCallback delegate when the operation is complete.

戻り値

非同期要求を参照する IAsyncResult インスタンス。An IAsyncResult instance that references the asynchronous request.

例外

address を解決するときにエラーが発生しました。An error is encountered when resolving address.

address は無効な IP アドレスです。address is an invalid IP address.

次のコード例では、BeginGetHostEntryメソッドを解決するには、IP アドレスをIPHostEntryインスタンス。The following code example uses the BeginGetHostEntry method to resolve an IP address to an IPHostEntry instance.

    // Signals when the resolve has finished.
public:
    static ManualResetEvent^ GetHostEntryFinished =
        gcnew ManualResetEvent(false);

    // define the state object for the callback. 
    // use hostName to correlate calls with the proper result.
    ref class ResolveState
    {
    public:
        String^ hostName;
        IPHostEntry^ resolvedIPs;

        ResolveState(String^ host)
        {
            hostName = host;
        }

        property IPHostEntry^ IPs 
        {
            IPHostEntry^ get()
            {
                return resolvedIPs;
            }

            void set(IPHostEntry^ IPs)
            {
                resolvedIPs = IPs;
            }
        }

        property String^ host 
        {
            String^ get()
            {
                return hostName;
            }

            void set(String^ host)
            {
                hostName = host;
            }
        }
    };

    // Record the IPs in the state object for later use.
    static void GetHostEntryCallback(IAsyncResult^ ar)
    {
        ResolveState^ ioContext = (ResolveState^)(ar->AsyncState);

        ioContext->IPs = Dns::EndGetHostEntry(ar);
        GetHostEntryFinished->Set();
    }


    // Determine the Internet Protocol(IP) addresses for this 
    // host asynchronously.
public:
    static void DoGetHostEntryAsync(String^ hostName)
    {
        GetHostEntryFinished->Reset();
        ResolveState^ ioContext = gcnew ResolveState(hostName);

        Dns::BeginGetHostEntry(ioContext->host,
            gcnew AsyncCallback(GetHostEntryCallback), ioContext);
        // Wait here until the resolve completes 
        // (the callback calls .Set())
        GetHostEntryFinished->WaitOne();

        Console::WriteLine("EndGetHostEntry({0}) returns:", ioContext->host);
      
        for (int i = 0; i < ioContext->IPs->AddressList->Length; i++)
        {
            Console::WriteLine("    {0}", ioContext->IPs->AddressList[i]->ToString());
        }

//      for each (IPAddress^ address in ioContext->IPs)
//      {
//          Console::WriteLine("{0} ", address);
//      }
    }
// Signals when the resolve has finished.
public static ManualResetEvent GetHostEntryFinished = 
    new ManualResetEvent(false);

// Define the state object for the callback. 
// Use hostName to correlate calls with the proper result.
public class ResolveState
{
    string hostName;
    IPHostEntry resolvedIPs;

    public ResolveState(string host)
    {
        hostName = host;
    }

    public IPHostEntry IPs
    {
        get { return resolvedIPs; }
        set { resolvedIPs = value; }
    }

    public string host
    {
        get { return hostName; }
        set { hostName = value; }
    }
}

// Record the IPs in the state object for later use.
public static void GetHostEntryCallback(IAsyncResult ar)
{
    ResolveState ioContext = (ResolveState)ar.AsyncState;
    ioContext.IPs = Dns.EndGetHostEntry(ar);
    GetHostEntryFinished.Set();
}

// Determine the Internet Protocol (IP) addresses for 
// this host asynchronously.
public static void DoGetHostEntryAsync(string hostname)
{
    GetHostEntryFinished.Reset();
    ResolveState ioContext= new ResolveState(hostname);

    Dns.BeginGetHostEntry(ioContext.host, 
        new AsyncCallback(GetHostEntryCallback), ioContext);

    // Wait here until the resolve completes (the callback 
    // calls .Set())
    GetHostEntryFinished.WaitOne();

    Console.WriteLine("EndGetHostEntry({0}) returns:", ioContext.host);

    foreach (IPAddress address in ioContext.IPs.AddressList)
    {
        Console.WriteLine($"    {address}");
    }
}
' Signals when the resolve has finished.
Dim Shared GetHostEntryFinished As ManualResetEvent = New ManualResetEvent(False)

' Define the state object for the callback. 
' Use hostName to correlate calls with the proper result.
Class ResolveState
    
    Dim hostName As String
    Dim resolvedIPs As IPHostEntry

    Public Sub New(host As String)
        hostName = host
    End Sub

    Public Property IPs AS IPHostEntry
        Get
            Return resolvedIPs
        End Get
        Set
            resolvedIPs = value
        End Set
    End Property

    Public Property host As String
        Get
            Return hostName
        End Get
        Set
            hostName = value
        End Set
    End Property

End Class

' Record the IPs in the state object for later use.
Shared Sub GetHostEntryCallback(ar As IAsyncResult)

    Dim ioContext As ResolveState = ar.AsyncState

    ioContext.IPs = Dns.EndGetHostEntry(ar)
    GetHostEntryFinished.Set()

End Sub

' Determine the Internet Protocol (IP) addresses for 
' this host asynchronously.
Shared Sub DoGetHostEntryAsync(hostname As String)
    
    GetHostEntryFinished.Reset()
    Dim ioContext As ResolveState = New ResolveState(hostname)

    Dns.BeginGetHostEntry(ioContext.host,AddressOf GetHostEntryCallback, ioContext)

    ' Wait here until the resolve completes (the callback 
    ' calls .Set())
    GetHostEntryFinished.WaitOne()

    Console.WriteLine($"EndGetHostEntry({ioContext.host}) returns:")

    Dim addresses As IPAddress() = ioContext.IPs.AddressList

    Dim index As Integer
    For index = 0 To addresses.Length - 1
        Console.WriteLine($"    {addresses(index)}")
    Next index

End Sub

注釈

BeginGetHostEntryメソッドは、DNS サーバーの IP アドレスと IP アドレスに関連付けられているエイリアスを非同期的にクエリします。The BeginGetHostEntry method asynchronously queries a DNS server for the IP addresses and aliases associated with an IP address.

このメンバーは、アプリケーションでネットワークのトレースを有効にした場合にトレース情報を出力します。Note This member emits trace information when you enable network tracing in your application. 詳細については、次を参照してください。ネットワークのトレースを .NET Framework でします。For more information, see Network Tracing in the .NET Framework.

非同期のBeginGetHostEntry操作を呼び出すことによって完了する必要があります、EndGetHostEntryメソッド。The asynchronous BeginGetHostEntry operation must be completed by calling the EndGetHostEntry method. 通常、メソッドは、によって呼び出される、requestCallbackを委任します。Typically, the method is invoked by the requestCallback delegate.

操作が完了するまで、このメソッドはブロックされません。This method does not block until the operation is complete. 操作が完了するまでにブロックするを使用して、GetHostEntryメソッド。To block until the operation is complete, use the GetHostEntry method.

詳細については、非同期プログラミング モデルを使用して、次を参照してくださいCalling Synchronous Methods Asynchronously。For detailed information about using the asynchronous programming model, see Calling Synchronous Methods Asynchronously

セキュリティ

DnsPermission
DNS 情報にアクセスします。for accessing DNS information. 関連付けられた列挙体。 UnrestrictedAssociated enumeration: Unrestricted

BeginGetHostEntry(String, AsyncCallback, Object) BeginGetHostEntry(String, AsyncCallback, Object) BeginGetHostEntry(String, AsyncCallback, Object) BeginGetHostEntry(String, AsyncCallback, Object)

ホスト名または IP アドレスを非同期的に IPHostEntry インスタンスに解決します。Asynchronously resolves a host name or IP address to an IPHostEntry instance.

public:
 static IAsyncResult ^ BeginGetHostEntry(System::String ^ hostNameOrAddress, AsyncCallback ^ requestCallback, System::Object ^ stateObject);
public static IAsyncResult BeginGetHostEntry (string hostNameOrAddress, AsyncCallback requestCallback, object stateObject);
static member BeginGetHostEntry : string * AsyncCallback * obj -> IAsyncResult
Public Shared Function BeginGetHostEntry (hostNameOrAddress As String, requestCallback As AsyncCallback, stateObject As Object) As IAsyncResult

パラメーター

hostNameOrAddress
String String String String

解決するホスト名または IP アドレス。The host name or IP address to resolve.

requestCallback
AsyncCallback AsyncCallback AsyncCallback AsyncCallback

操作の完了時に呼び出すメソッドを参照する AsyncCallback デリゲート。An AsyncCallback delegate that references the method to invoke when the operation is complete.

stateObject
Object Object Object Object

操作に関する情報を格納するユーザー定義のオブジェクト。A user-defined object that contains information about the operation. このオブジェクトは、操作の完了時に requestCallback デリゲートに渡されます。This object is passed to the requestCallback delegate when the operation is complete.

戻り値

非同期要求を参照する IAsyncResult インスタンス。An IAsyncResult instance that references the asynchronous request.

例外

hostNameOrAddressnullです。hostNameOrAddress is null.

hostNameOrAddress の長さが 255 文字を超えています。The length of hostNameOrAddress is greater than 255 characters.

hostNameOrAddress を解決するときにエラーが発生しました。An error is encountered when resolving hostNameOrAddress.

hostNameOrAddress は無効な IP アドレスです。hostNameOrAddress is an invalid IP address.

次のコード例では、BeginGetHostEntryメソッドを解決するには、IP アドレスをIPHostEntryインスタンス。The following code example uses the BeginGetHostEntry method to resolve an IP address to an IPHostEntry instance.

    // Signals when the resolve has finished.
public:
    static ManualResetEvent^ GetHostEntryFinished =
        gcnew ManualResetEvent(false);

    // define the state object for the callback. 
    // use hostName to correlate calls with the proper result.
    ref class ResolveState
    {
    public:
        String^ hostName;
        IPHostEntry^ resolvedIPs;

        ResolveState(String^ host)
        {
            hostName = host;
        }

        property IPHostEntry^ IPs 
        {
            IPHostEntry^ get()
            {
                return resolvedIPs;
            }

            void set(IPHostEntry^ IPs)
            {
                resolvedIPs = IPs;
            }
        }

        property String^ host 
        {
            String^ get()
            {
                return hostName;
            }

            void set(String^ host)
            {
                hostName = host;
            }
        }
    };

    // Record the IPs in the state object for later use.
    static void GetHostEntryCallback(IAsyncResult^ ar)
    {
        ResolveState^ ioContext = (ResolveState^)(ar->AsyncState);

        ioContext->IPs = Dns::EndGetHostEntry(ar);
        GetHostEntryFinished->Set();
    }


    // Determine the Internet Protocol(IP) addresses for this 
    // host asynchronously.
public:
    static void DoGetHostEntryAsync(String^ hostName)
    {
        GetHostEntryFinished->Reset();
        ResolveState^ ioContext = gcnew ResolveState(hostName);

        Dns::BeginGetHostEntry(ioContext->host,
            gcnew AsyncCallback(GetHostEntryCallback), ioContext);
        // Wait here until the resolve completes 
        // (the callback calls .Set())
        GetHostEntryFinished->WaitOne();

        Console::WriteLine("EndGetHostEntry({0}) returns:", ioContext->host);
      
        for (int i = 0; i < ioContext->IPs->AddressList->Length; i++)
        {
            Console::WriteLine("    {0}", ioContext->IPs->AddressList[i]->ToString());
        }

//      for each (IPAddress^ address in ioContext->IPs)
//      {
//          Console::WriteLine("{0} ", address);
//      }
    }
// Signals when the resolve has finished.
public static ManualResetEvent GetHostEntryFinished = 
    new ManualResetEvent(false);

// Define the state object for the callback. 
// Use hostName to correlate calls with the proper result.
public class ResolveState
{
    string hostName;
    IPHostEntry resolvedIPs;

    public ResolveState(string host)
    {
        hostName = host;
    }

    public IPHostEntry IPs
    {
        get { return resolvedIPs; }
        set { resolvedIPs = value; }
    }

    public string host
    {
        get { return hostName; }
        set { hostName = value; }
    }
}

// Record the IPs in the state object for later use.
public static void GetHostEntryCallback(IAsyncResult ar)
{
    ResolveState ioContext = (ResolveState)ar.AsyncState;
    ioContext.IPs = Dns.EndGetHostEntry(ar);
    GetHostEntryFinished.Set();
}

// Determine the Internet Protocol (IP) addresses for 
// this host asynchronously.
public static void DoGetHostEntryAsync(string hostname)
{
    GetHostEntryFinished.Reset();
    ResolveState ioContext= new ResolveState(hostname);

    Dns.BeginGetHostEntry(ioContext.host, 
        new AsyncCallback(GetHostEntryCallback), ioContext);

    // Wait here until the resolve completes (the callback 
    // calls .Set())
    GetHostEntryFinished.WaitOne();

    Console.WriteLine("EndGetHostEntry({0}) returns:", ioContext.host);

    foreach (IPAddress address in ioContext.IPs.AddressList)
    {
        Console.WriteLine($"    {address}");
    }
}
' Signals when the resolve has finished.
Dim Shared GetHostEntryFinished As ManualResetEvent = New ManualResetEvent(False)

' Define the state object for the callback. 
' Use hostName to correlate calls with the proper result.
Class ResolveState
    
    Dim hostName As String
    Dim resolvedIPs As IPHostEntry

    Public Sub New(host As String)
        hostName = host
    End Sub

    Public Property IPs AS IPHostEntry
        Get
            Return resolvedIPs
        End Get
        Set
            resolvedIPs = value
        End Set
    End Property

    Public Property host As String
        Get
            Return hostName
        End Get
        Set
            hostName = value
        End Set
    End Property

End Class

' Record the IPs in the state object for later use.
Shared Sub GetHostEntryCallback(ar As IAsyncResult)

    Dim ioContext As ResolveState = ar.AsyncState

    ioContext.IPs = Dns.EndGetHostEntry(ar)
    GetHostEntryFinished.Set()

End Sub

' Determine the Internet Protocol (IP) addresses for 
' this host asynchronously.
Shared Sub DoGetHostEntryAsync(hostname As String)
    
    GetHostEntryFinished.Reset()
    Dim ioContext As ResolveState = New ResolveState(hostname)

    Dns.BeginGetHostEntry(ioContext.host,AddressOf GetHostEntryCallback, ioContext)

    ' Wait here until the resolve completes (the callback 
    ' calls .Set())
    GetHostEntryFinished.WaitOne()

    Console.WriteLine($"EndGetHostEntry({ioContext.host}) returns:")

    Dim addresses As IPAddress() = ioContext.IPs.AddressList

    Dim index As Integer
    For index = 0 To addresses.Length - 1
        Console.WriteLine($"    {addresses(index)}")
    Next index

End Sub

注釈

BeginGetHostEntryメソッドは、ホスト名に関連付けられている IP アドレスまたは IP アドレスの DNS サーバーを照会します。The BeginGetHostEntry method queries a DNS server for the IP address that is associated with a host name or IP address.

このメンバーは、アプリケーションでネットワークのトレースを有効にした場合にトレース情報を出力します。Note This member emits trace information when you enable network tracing in your application. 詳細については、次を参照してください。ネットワークのトレースを .NET Framework でします。For more information, see Network Tracing in the .NET Framework.

非同期のBeginGetHostEntry操作を呼び出すことによって完了する必要があります、EndGetHostEntryメソッド。The asynchronous BeginGetHostEntry operation must be completed by calling the EndGetHostEntry method. 通常、メソッドは、によって呼び出される、requestCallbackを委任します。Typically, the method is invoked by the requestCallback delegate.

操作が完了するまで、このメソッドはブロックされません。This method does not block until the operation is complete. 操作が完了するまでにブロックするを使用して、GetHostEntryメソッド。To block until the operation is complete, use the GetHostEntry method.

詳細については、非同期プログラミング モデルを使用して、次を参照してください。 Calling Synchronous Methods Asynchronouslyします。For detailed information about using the asynchronous programming model, see Calling Synchronous Methods Asynchronously.

セキュリティ

DnsPermission
DNS 情報にアクセスします。for accessing DNS information. 関連付けられた列挙体。 UnrestrictedAssociated enumeration: Unrestricted

適用対象