title: querying for dns aliases
body: <p>I found some <a href="http://msdn.microsoft.com/en-us/library/system.net.dns.gethostbyaddress(VS.71).aspx" rel="noreferrer">code</a> from the msdn site (Code included below), which looks like it will return all dns aliases for a given server.  I've implemented the code in a cosole app, which should allow me to enter the host name of a server and it should return all dns alias names.  I enter the host name of a server in our domain known to have aliases (I can ping the host and the aliases and they all resolve to the same IP), but this code does not find the alias names.  Obvously my understanding of dns aliases and/or the code is lacking... please educate me...</p>
  
  <pre><code>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 &lt; alias.Length; index++)
          {
              Console.WriteLine(alias[index]);
          }
          Console.WriteLine("\nIP address list : ");
          for (int index = 0; index &lt; 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();
  }
  </code></pre>