Dns.BeginGetHostEntry 메서드

정의

비동기적으로 호스트 이름 또는 IP 주소를 IPHostEntry 인스턴스로 확인합니다.Asynchronously resolves a host name or IP address to an IPHostEntry instance.

오버로드

BeginGetHostEntry(IPAddress, AsyncCallback, Object)

비동기적으로 IP 주소를 IPHostEntry 인스턴스로 확인합니다.Asynchronously resolves an IP address to an IPHostEntry instance.

BeginGetHostEntry(String, AsyncCallback, Object)

비동기적으로 호스트 이름 또는 IP 주소를 IPHostEntry 인스턴스로 확인합니다.Asynchronously resolves a host name or IP address to an IPHostEntry instance.

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

확인할 IP 주소입니다.The IP address to resolve.

requestCallback
AsyncCallback

작업이 완료되었을 때 호출할 메서드를 참조하는 AsyncCallback 대리자입니다.An AsyncCallback delegate that references the method to invoke when the operation is complete.

stateObject
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.

예외

addressnull인 경우address is null.

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 메서드는 IP 주소와 연결 된 IP 주소 및 별칭에 대해 DNS 서버를 비동기적으로 쿼리 합니다.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.

비동기 프로그래밍 모델을 사용 하는 방법에 대 한 자세한 내용은 동기 메서드를 비동기적으로 호출 을 참조 하세요.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)

비동기적으로 호스트 이름 또는 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

확인할 호스트 이름 또는 IP 주소입니다.The host name or IP address to resolve.

requestCallback
AsyncCallback

작업이 완료되었을 때 호출할 메서드를 참조하는 AsyncCallback 대리자입니다.An AsyncCallback delegate that references the method to invoke when the operation is complete.

stateObject
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 메서드는 DNS 서버에서 호스트 이름 또는 IP 주소와 연결 된 IP 주소를 쿼리 합니다.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.

비동기 프로그래밍 모델을 사용 하는 방법에 대 한 자세한 내용은 동기 메서드를 비동기적으로 호출을 참조 하세요.For detailed information about using the asynchronous programming model, see Calling Synchronous Methods Asynchronously.

보안

DnsPermission
DNS 정보에 액세스 합니다.for accessing DNS information. 연결 된 열거형: UnrestrictedAssociated enumeration: Unrestricted

적용 대상