Dns.GetHostByName(String) 메서드

정의

경고

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

지정된 DNS 호스트 이름에서 DNS 정보를 가져옵니다.Gets the DNS information for the specified DNS host name.

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

매개 변수

hostName
String

호스트의 DNS 이름입니다.The DNS name of the host.

반환

hostName에 지정된 주소의 호스트 정보를 포함하는 IPHostEntry 개체입니다.An IPHostEntry object that contains host information for the address specified in hostName.

특성

예외

hostName이(가) null인 경우hostName is null.

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

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

예제

다음 예제에서는 GetHostByName 메서드를 사용 하 여 지정 된 DNS 호스트 이름에 대 한 DNS 정보를 가져옵니다.The following example uses the GetHostByName method to get the DNS information for the specified DNS host name.

try
{
   IPHostEntry^ hostInfo = Dns::GetHostByName( hostName );
   
   // 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 ( Exception^ e ) 
{
   Console::WriteLine( "Exception caught!!!" );
   Console::WriteLine( "Source : {0}", e->Source );
   Console::WriteLine( "Message : {0}", e->Message );
}
 try 
 {
    IPHostEntry hostInfo = Dns.GetHostByName(hostName);
    // 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(Exception e)
 {
     Console.WriteLine("Exception caught!!!");
     Console.WriteLine("Source : " + e.Source);
     Console.WriteLine("Message : " + e.Message);
 }
Public Sub DisplayHostName(hostName As [String])
    Try
        ' Call the GetHostByName method, passing a DNS style host name(for example,
        ' "www.contoso.com") as an argument to obtain an IPHostEntry instance, that 
        ' contains information for the specified host.
        
        Dim hostInfo As IPHostEntry = Dns.GetHostByName(hostName)
        ' 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 Exception
        Console.WriteLine("Exception caught!!!")
        Console.WriteLine(("Source : " + e.Source))
        Console.WriteLine(("Message : " + e.Message))
    End Try

설명

GetHostByName 메서드는 인터넷 DNS 서버에 호스트 정보를 쿼리 합니다.The GetHostByName method queries the Internet DNS server for host information. 호스트 이름으로 빈 문자열을 전달 하는 경우이 메서드는 로컬 컴퓨터에 대 한 표준 호스트 이름을 검색 합니다.If you pass an empty string as the host name, this method retrieves the standard host name for the local computer.

DNS 정보에 대 한 비동기 액세스의 경우 BeginGetHostByNameEndGetHostByName 메서드를 사용 합니다.For asynchronous access to DNS information, use the BeginGetHostByName and EndGetHostByName methods.

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

적용 대상