2009-09-24 3 views
4

msdn 사이트 (아래 코드 포함)에서 일부 code을 발견했습니다. 그러면 해당 서버에 대한 모든 dns 별칭이 반환됩니다. 나는 cosole app에 코드를 구현했다.이 코드는 서버의 호스트 이름을 입력 할 수 있어야하며 모든 dns 별칭 이름을 반환해야한다. 별칭이있는 것으로 알려진 도메인의 서버 호스트 이름을 입력합니다 (호스트와 별칭에 대해 ping을 수행 할 수 있으며 모두 동일한 IP로 해석 됨). 그러나이 코드는 별칭 이름을 찾지 않습니다. 이름 쿼리하는 경우 Obvously DNS 별칭 및/또는 코드 부족에 대한 이해 나 ... 교육 제발 ... DNS 이름에DNS 별칭에 대한 쿼리

static void Main(string[] args) 
{ 
    Console.Write("Host? (Enter for local): "); 
    string strHost = Console.ReadLine(); 
    if (strHost.Trim().Length == 0) 
    { 
     strHost = System.Net.Dns.GetHostName(); 
    } 

    try 
    { 
     //System.Net.IPAddress hostIPAddress = System.Net.IPAddress.Parse(strHost); 
     System.Net.IPHostEntry hostInfo = System.Net.Dns.GetHostByName(strHost);//.GetHostByAddress(hostIPAddress); 
     // Get the IP address list that resolves to the host names contained in 
     // the Alias property. 
     System.Net.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 (System.Net.Sockets.SocketException e) 
    { 
     Console.WriteLine("SocketException caught!!!"); 
     Console.WriteLine("Source : " + e.Source); 
     Console.WriteLine("Message : " + e.Message); 
    } 
    catch (FormatException e) 
    { 
     Console.WriteLine("FormatException 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); 
    } 

    Console.WriteLine("Any key to continue..."); 
    Console.ReadKey(); 
} 

답변

4

는, 별명의 목록은 비어있을 것입니다 CNAME 레코드가 있습니다. 별칭 목록은 궁극적 인 이름을 얻기 위해 해결되어야하는 모든 CNAME을 제공합니다.

는 다음과 같은 문제를 고려 : 그것은 불가능하다

  • 주어진 이름에 대한 모든 CNAME이를 찾기 위해 (즉 프로토콜을 지원하지 않습니다). 이것은 글로벌 DNS 전체를 검색해야하므로 실행 불가능합니다.
  • 앨리어싱은 CNAME에 의해서만 발생하는 것은 아니지만 동일한 주소 (A) 레코드를 가진 여러 호스트 이름에서도 발생할 수 있습니다. 이 경우 다른 사람의 별칭이 아니라 동일한 IP 주소를 가리키고 있습니다. 다시 프로토콜은 IP 주소에 대한 모든 A 레코드를 찾는 것을 지원하지 않습니다 (역방향 조회에서 일부를 찾을 수도 있음).