msdn サイトからいくつかのコードを見つけました (コードは以下に含まれています)。これは、特定のサーバーのすべての dns エイリアスを返すようです。サーバーのホスト名を入力できるようにする必要があるcosoleアプリにコードを実装し、すべてのDNSエイリアス名を返す必要があります。エイリアスを持つことがわかっているドメイン内のサーバーのホスト名を入力します (ホストとエイリアスに ping を実行すると、それらはすべて同じ IP に解決されます) が、このコードではエイリアス名が見つかりません。明らかに、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();
}