Request dns aliases

I found some code from the msdn website (the code below) that seems to return all the DNS aliases for this server. I injected the code into a savior application that should allow me to enter the host name of the server and should return all the DNS alias names. I enter the host name of the server in our domain, which, as you know, has aliases (I can ping the host and aliases, and all of them resolve the same IP address), but this code does not find aliases. Obviously, my understanding of dns aliases and / or code is missing ... please enlighten me ...

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();
}
+5
source share
1 answer

DNS , , , CNAME; CNAME, , .

:

  • (.. ), CNAME . , DNS.
  • aliasing CNAME, , (A). , , IP-. , A IP- ( ).
+5
source

All Articles