title: How to get IP address of network adapter
body: <p>I use this code to get the available IPv4 addresses:</p>
  
  <pre><code>static void Main(string[] args)
      {
          string host = System.Net.Dns.GetHostName();
          System.Net.IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(host);
          System.Net.IPAddress[] ipAddr = ipEntry.AddressList;
          for (int i = 0; i &lt; ipAddr.Length; i++)
          {
              if (ipAddr[i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                  Console.WriteLine( ipAddr[i]);
  
          }
      }
  </code></pre>
  
  <p>For my machine this currently gives:</p>
  
  <p>192.168.1.11</p>
  
  <p>192.168.240.1</p>
  
  <p>192.168.182.1</p>
  
  <p>10.1.1.121</p>
  
  <p>whereas 192.168.1.11 is my network adapter, the next two are from VMware Network, and 10.1.1.121 is from a currently active OpenVPN connection.</p>
  
  <p>How can I reliably detect the IPv4 address 192.168.1.11 (= network adapter) only?
  I guess that it's just incidentally on the first place.</p>
  
  <p>Thanks, Robert</p>