I am trying to get IP address on local machine:
    private string GetIP()
    {
        string strHostName = "";
        strHostName = System.Net.Dns.GetHostName();
        IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
        IPAddress[] addr = ipEntry.AddressList;
        foreach (IPAddress ipaddr in addr)
        {
            if (ipaddr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                return ipaddr.ToString();
        }
        return "IP error";                                   
    }
However I can't find a way to identify which interface is the one i need. For example:

I am lucky that the one i need is second in the list. But if it were in the back i would get IP of a wrong interface. How to check if I am getting IP for local area connection (or in general, the interface responsible for the connection).
 
     
     
    