title: Get local system ip address using c#
body: <p>I am looking for method which identifies if the system is connected to the network or gets the local ip address when virtual machines are install on the system.
  This is the code which returns the local ip address:</p>
  
  <pre><code> public static string LocalIPAddress()
          {
              IPHostEntry host;
              string localIP = "";
              host = Dns.GetHostEntry(Dns.GetHostName());
              foreach (IPAddress ip in host.AddressList)
              {
                  if (ip.AddressFamily.ToString() == "InterNetwork")
                  {
                      localIP = ip.ToString();
                  }
              }
              return localIP;
          }
  </code></pre>
  
  <p>But when the system is not connected to the network it returns the other VM ip address.<br>
  I also found this method
  <code>System.Net.NetworkInformation.NetworkInterface.isconnected</code> method available but it returns true even when the network cable is unplugged.<br>
  Is there any way to find out if the system is connected or not?</p>