Una forma sencilla de detectar el estado de las interfaces de red:
using System.Net.NetworkInformation;
namespace Examples.Net.AddressChanges
{
public class NetworkingExample
{
public static void Main()
{
NetworkChange.NetworkAddressChanged += new
NetworkAddressChangedEventHandler(AddressChangedCallback);
NetworkChange.NetworkAvailabilityChanged += new
NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged);
Console.ReadLine();
}
static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
{
Console.WriteLine(e.IsAvailable);
}
static void AddressChangedCallback(object sender, EventArgs e)
{
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in adapters)
{
Console.WriteLine(" {0} is {1}", adapter.Name, adapter.OperationalStatus);
}
}
}
}
Tomé el ejemplo de la documentación por si algún día necesito hacer algo parecido. 😀