Dns.Resolve(String) 메서드

정의

경고

이 API는 현재 사용되지 않습니다.

DNS 호스트 이름 또는 IP 주소를 IPHostEntry 인스턴스로 확인합니다.Resolves a DNS host name or IP address to an IPHostEntry instance.

public:
 static System::Net::IPHostEntry ^ Resolve(System::String ^ hostName);
[System.Obsolete("Use GetHostEntry instead")]
[System.Obsolete("Resolve is obsoleted for this type, please use GetHostEntry instead. https://go.microsoft.com/fwlink/?linkid=14202")]
[System.Obsolete("Resolve is obsoleted for this type, please use GetHostEntry instead. https://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Net.IPHostEntry Resolve (string hostName);
static member Resolve : string -> System.Net.IPHostEntry
Public Shared Function Resolve (hostName As String) As IPHostEntry

매개 변수

hostName
String

DNS 스타일의 호스트 이름 또는 IP 주소입니다.A DNS-style host name or IP address.

반환

hostName에 지정된 호스트의 주소 정보를 포함하는 IPHostEntry 인스턴스입니다.An IPHostEntry instance that contains address information about the host specified in hostName.

특성

예외

hostNamenull입니다.hostName is null.

hostName의 길이가 255자를 넘습니다.The length of hostName is greater than 255 characters.

hostName을 확인할 때 오류가 발생한 경우An error is encountered when resolving hostName.

예제

다음 예제에서는 Resolve 메서드를 사용 하 여 IP 주소를 IPHostEntry 인스턴스로 확인 합니다.The following example uses the Resolve method to resolve an IP address to an IPHostEntry instance.

try
{
   IPHostEntry^ hostInfo = Dns::Resolve( hostString );
   
   // Get the IP address list that resolves to the host names contained in the
   // Alias property.
   array<IPAddress^>^address = hostInfo->AddressList;
   
   // Get the alias names of the addresses in the IP address list.
   array<String^>^alias = hostInfo->Aliases;
   Console::WriteLine( "Host name : {0}", hostInfo->HostName );
   Console::WriteLine( "\nAliases : " );
   for ( int index = 0; index < alias->Length; index++ )
   {
      Console::WriteLine( alias[ index ] );

   }
   Console::WriteLine( "\nIP Address list :" );
   for ( int index = 0; index < address->Length; index++ )
   {
      Console::WriteLine( address[ index ] );

   }
}
catch ( SocketException^ e ) 
{
   Console::WriteLine( "SocketException caught!!!" );
   Console::WriteLine( "Source : {0}", e->Source );
   Console::WriteLine( "Message : {0}", e->Message );
}
catch ( ArgumentNullException^ e ) 
{
   Console::WriteLine( "ArgumentNullException caught!!!" );
   Console::WriteLine( "Source : {0}", e->Source );
   Console::WriteLine( "Message : {0}", e->Message );
}
catch ( NullReferenceException^ e ) 
{
   Console::WriteLine( "NullReferenceException caught!!!" );
   Console::WriteLine( "Source : {0}", e->Source );
   Console::WriteLine( "Message : {0}", e->Message );
}
catch ( Exception^ e ) 
{
   Console::WriteLine( "Exception caught!!!" );
   Console::WriteLine( "Source : {0}", e->Source );
   Console::WriteLine( "Message : {0}", e->Message );
}
try {
    IPHostEntry hostInfo = Dns.Resolve(hostString);
    // Get the IP address list that resolves to the host names contained in the 
    // Alias property.
    IPAddress[] address = hostInfo.AddressList;
    // Get the alias names of the addresses in the IP address list.
    String[] alias = hostInfo.Aliases;

    Console.WriteLine("Host name : " + hostInfo.HostName);
    Console.WriteLine("\nAliases : ");
    for(int index=0; index < alias.Length; index++) {
      Console.WriteLine(alias[index]);
    } 
    Console.WriteLine("\nIP Address list :");
    for(int index=0; index < address.Length; index++) {
       Console.WriteLine(address[index]);
    }
 }
 catch(SocketException e) 
 {
    Console.WriteLine("SocketException caught!!!");
    Console.WriteLine("Source : " + e.Source);
    Console.WriteLine("Message : " + e.Message);
 }
 catch(ArgumentNullException e)
 {
Console.WriteLine("ArgumentNullException caught!!!");
    Console.WriteLine("Source : " + e.Source);
    Console.WriteLine("Message : " + e.Message);
 }
 catch(NullReferenceException e)
 {
     Console.WriteLine("NullReferenceException caught!!!");
     Console.WriteLine("Source : " + e.Source);
     Console.WriteLine("Message : " + e.Message);
 }
 catch(Exception e)
 {
     Console.WriteLine("Exception caught!!!");
     Console.WriteLine("Source : " + e.Source);
     Console.WriteLine("Message : " + e.Message);
 }
Try
    ' Call the Resolve method passing a DNS style host name or an IP address in 
    ' dotted-quad notation (for example, "www.contoso.com" or "207.46.131.199") to 
    ' obtain an IPHostEntry instance that contains address information for the 
    ' specified host.
    Dim hostInfo As IPHostEntry = Dns.Resolve(hostString)
    ' Get the IP address list that resolves to the host names contained in the Alias 
    ' property.
    Dim address As IPAddress() = hostInfo.AddressList
    ' Get the alias names of the addresses in the IP address list.
    Dim [alias] As [String]() = hostInfo.Aliases

    Console.WriteLine(("Host name : " + hostInfo.HostName))
    Console.WriteLine(ControlChars.Cr + "Aliases : ")
    Dim index As Integer
    For index = 0 To [alias].Length - 1
        Console.WriteLine([alias](index))
    Next index
    Console.WriteLine(ControlChars.Cr + "IP Address list :")

    For index = 0 To address.Length - 1
        Console.WriteLine(address(index))
    Next index
Catch e As SocketException
    Console.WriteLine("SocketException caught!!!")
    Console.WriteLine(("Source : " + e.Source))
    Console.WriteLine(("Message : " + e.Message))
Catch e As ArgumentNullException
    Console.WriteLine("ArgumentNullException caught!!!")
    Console.WriteLine(("Source : " + e.Source))
    Console.WriteLine(("Message : " + e.Message))
Catch e As NullReferenceException
    Console.WriteLine("NullReferenceException caught!!!")
    Console.WriteLine(("Source : " + e.Source))
    Console.WriteLine(("Message : " + e.Message))
Catch e As Exception
    Console.WriteLine("Exception caught!!!")
    Console.WriteLine(("Source : " + e.Source))
    Console.WriteLine(("Message : " + e.Message))
End Try

설명

Resolve 메서드는 DNS 서버에서 호스트 이름 또는 IP 주소와 연결 된 IP 주소를 쿼리 합니다.The Resolve method queries a DNS server for the IP address associated with a host name or IP address.

hostName 여러 IP 주소와 연결 된 DNS 스타일 호스트 이름인 경우 해당 호스트 이름으로 확인 되는 첫 번째 IP 주소만 반환 됩니다.When hostName is a DNS-style host name associated with multiple IP addresses, only the first IP address that resolves to that host name is returned.

Ipv6Element.Enabled 속성이 true로 설정 된 경우 반환 된 IPHostEntry 인스턴스의 Aliases 속성은이 메서드로 채워지지 않으며 항상 비어 있습니다.If the Ipv6Element.Enabled property is set to true, the Aliases property of the IPHostEntry instance returned is not populated by this method and will always be empty.

참고

이 멤버는 애플리케이션에서 네트워크 추적을 사용 하도록 설정 하면 추적 정보를 내보냅니다.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.

보안

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

적용 대상