Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. network change event/Compare

network change event/Compare

Scheduled Pinned Locked Moved C#
csharpdatabasesysadmindata-structuresquestion
2 Posts 2 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    geomeo123
    wrote on last edited by
    #1

    I'm trying to detect when an ethernet cable is unplugged from a computer or plugged back in. I have some devices that when plugged in they come up as Unidentified Network(which is normal for the specific device). I'm not looking for internet connection or have anything to do with that. And I think this code works as a trigger:

    NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
    private static void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
    {

    NetworkInterface\[\] adapters = NetworkInterface.GetAllNetworkInterfaces();
    foreach (NetworkInterface n in adapters)
    {
       
    
        
       MessageBox.Show(n.Name.ToString() + n.OperationalStatus.ToString());
    }
    

    }

    What I need to do now is to figure out which network adapter was unplugged. I intend to get the operational status of each network adapter. Store it, ask user to power cycle the device and then compare with the stored value(s) to figure out which one has changed from up to down. I'm not sure what the best method to do this would be. Should I do this as an array, list or is there an easier way?

    R 1 Reply Last reply
    0
    • G geomeo123

      I'm trying to detect when an ethernet cable is unplugged from a computer or plugged back in. I have some devices that when plugged in they come up as Unidentified Network(which is normal for the specific device). I'm not looking for internet connection or have anything to do with that. And I think this code works as a trigger:

      NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
      private static void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
      {

      NetworkInterface\[\] adapters = NetworkInterface.GetAllNetworkInterfaces();
      foreach (NetworkInterface n in adapters)
      {
         
      
          
         MessageBox.Show(n.Name.ToString() + n.OperationalStatus.ToString());
      }
      

      }

      What I need to do now is to figure out which network adapter was unplugged. I intend to get the operational status of each network adapter. Store it, ask user to power cycle the device and then compare with the stored value(s) to figure out which one has changed from up to down. I'm not sure what the best method to do this would be. Should I do this as an array, list or is there an easier way?

      R Offline
      R Offline
      RedDk
      wrote on last edited by
      #2

      Surely this return will aid in your finding a good answer to a problem: CP Search[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups