title: How do I get the network interface and its right IPv4 address?
body: <p>I need to know how to get all network interfaces with their <a href="http://en.wikipedia.org/wiki/IPv4" rel="noreferrer">IPv4</a> address. <i>Or just wireless and Ethernet.</i></p>
  
  <p>To get all network interfaces details I use this:</p>
  
  <pre><code>foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces()) {
      if(ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
         ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) {
  
          Console.WriteLine(ni.Name);
      }
  }
  </code></pre>
  
  <p>And to get the all hosted IPv4 addresses of the computer:</p>
  
  <pre><code>IPAddress [] IPS = Dns.GetHostAddresses(Dns.GetHostName());
  foreach (IPAddress ip in IPS) {
      if (ip.AddressFamily == AddressFamily.InterNetwork) {
  
          Console.WriteLine("IP address: " + ip);
      }
  }
  </code></pre>
  
  <p>But how to get the network interface and its right ipv4 address?</p>