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:
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;
}
But when the system is not connected to the network it returns the other VM ip address.
I also found this method
System.Net.NetworkInformation.NetworkInterface.isconnected
method available but it returns true even when the network cable is unplugged.
Is there any way to find out if the system is connected or not?