I need to check if a network interface is currently connected to a network, disconnected, or if it's been disabled. Consider the gross code below:
NetworkInterface[] nics = NetworkInterface;
while(true)
{
Console.WriteLine(nics[4].OperationalStatus);
}
What this never ending loop does is check the operational status of a network interface card. When the loop starts, the status is Up, but when I disconnect from the network or manually disable that NIC, operational status will remain Up.
How can I check if a specific NIC is connected, disconnected, or disabled? I would like to accomplish this without having to ping an external source.
Thanks!