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();
}