title: C# Get Active NIC IPv4 Address
body: <p>I have multiple network cards on my computer. (Because of VMWare)</p>
  
  <p>How can I find the IPv4 address of the active card. I mean if I send a ping in a terminal and intercept packet in WireShark, I want the address of "Source".</p>
  
  <p>I thought of checking every network interface and look if GateWay is empty or null ? Or maybe ping 127.0.0.1 and get the IP source of the ping request ? But cannot implement it.</p>
  
  <p>For now I have this code which i found on StackOverFlow</p>
  
  <pre><code> public static string GetLocalIpAddress()
          {
              var host = Dns.GetHostEntry(Dns.GetHostName());
              return host.AddressList.First(h =&gt; h.AddressFamily == AddressFamily.InterNetwork).ToString();
          }
  </code></pre>
  
  <p>But it gets me the IP of the VmWare card. But I don't know what else that "<code>.First()</code>" I could use.</p>