title: C# Resolve hostname with Dns to IP Address
body: <p>Got this program i am writing in my office in C#.</p>
  <p>So i can read all Computer Names From the Domain, fill them into a List and print them out.</p>
  <p>Using this Code :</p>
  <pre><code>    `private void FindComputersInAD()
      {
      List&lt;string&gt; computerNames = new List&lt;string&gt;();
          DirectoryContext dirCtx = new DirectoryContext(DirectoryContextType.Domain, &quot;domain.com&quot;);
          using (Domain usersDomain = Domain.GetDomain(dirCtx))
          using (DirectorySearcher adsearcher = new DirectorySearcher(usersDomain.GetDirectoryEntry()))
          {
              adsearcher.Filter = (&quot;(objectCategory=computer)&quot;);                                                                                                          
              adsearcher.SizeLimit = 0;
              adsearcher.PageSize = 250;
  
              // Let searcher know which properties are going to be used, and only load those
              adsearcher.PropertiesToLoad.Add(&quot;name&quot;);
  
              foreach (SearchResult searchResult in adsearcher.FindAll())
              {
                  if (searchResult.Properties[&quot;name&quot;].Count &gt; 0)
                  {
                      string computer = (string)searchResult.Properties[&quot;name&quot;][0];                      
                      computerNames.Add(computer);
                  }
              }
          }
          computerNames.Sort();
          computerNames.ForEach(Console.WriteLine);
      }`
  </code></pre>
  <p>Now that i got all the Computer Names, i would like to get their IP Addresses as well.
  But there is no such property.</p>
  <p>I googled a lot and tried a few things but nothing works.</p>
  <p>Can I use the DNS class to do this ?</p>
  <p>I use this method to get the Host IP Address :</p>
  <pre><code>private void GetLocalIPAddress()
      {
          string _subString;
          var _host = Dns.GetHostEntry(Dns.GetHostName());
          foreach (var _ip in _host.AddressList)
          {
              if (_ip.AddressFamily == AddressFamily.InterNetwork)
              {
                  _subString = _ip.ToString().Substring(_ip.ToString().Length - 2);
                  //When a IP Address ends with .1, don't add it to the List.
                  if (_subString != &quot;.1&quot;)
                  {
                      _hostIPAddress = _ip.ToString();
                  }
              }
          }
      }
  </code></pre>
  <p>Can I use this also somehow to get the IP Addresses of the Computers ?</p>
  <p>I would be very happy if you can help me :)</p>
  <p>Thanks in advance</p>