title: Ethernet cable disconnection detection in C#
body: <p>I need to detect the Ethernet cable disconnection in the system, for the same I'm using the following code to detect the changes in all the networks available in the system.</p>
  <pre><code>using System;
  using System.Net;
  using System.Net.NetworkInformation;
  
  namespace Examples.Net.AddressChanges
  {
      public class NetworkingExample
      {
          public static void Main()
          {
              NetworkChange.NetworkAddressChanged += new
              NetworkAddressChangedEventHandler(AddressChangedCallback);
              Console.WriteLine(&quot;Listening for address changes. Press any key to exit.&quot;);
              Console.ReadLine();
          }
          static void AddressChangedCallback(object sender, EventArgs e)
          {
  
              NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
              foreach (NetworkInterface n in adapters)
              {
                  Console.WriteLine(&quot;   {0} is {1}&quot;, n.Name, n.OperationalStatus);
              }
          }
      }
  }
  </code></pre>
  <p>My requirement, is to run a set of code when the &quot;operational status&quot; of &quot;Ethernet&quot; is &quot;down&quot; and another set of code when the &quot;operational status&quot; of &quot;Ethernet&quot; is &quot;Up&quot;.</p>
  <p>I'm pretty new to this, so I'm not able to use the operational status to do the required programming.
  Can anyone please help me with this?</p>