title: How to get IP address of network adapter used to access the internet
body: <p>I'm wondering if there's a reliable way of finding the IPv4 address of the network adapter in my machine which is used to access the internet (since this is the one I'd like to bind my server to). I used to get a list of local ip addresses like this:</p>
  
  <pre><code>IPAddress ip = System.Net.Dns.GetHostByName(Environment.MachineName).AddressList[0];
  </code></pre>
  
  <p>And it worked fine but today it failed because the IP address I was looking for was not the first one in this address list but the 3rd one (since I had 2 virtual machines running and both of these created a virtual adapter).</p>
  
  <p>Any advice would be much appreciated.</p>