Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Be informed when a network cable is plugged in / Wifi connected

I'm implementing in C# a discovery protocol (DNS-SD). I've a small problem: when my program is running, I need to detect when a new connection is established (network cable plugged or wifi joined), to announce myself on those network too.

But how to detect this? I've seen some code to get the current state of a network card, but no event, and I want to avoid to make some polling on the network cards states.

like image 647
J4N Avatar asked Feb 26 '13 09:02

J4N


People also ask

When I plug in Ethernet does it turn off Wi-Fi?

Windows does not turn off the Wi-Fi connection automatically when you connect an Ethernet cable. You have to do it manually -- unless you use this nifty method that's easy enough to do even if you aren't tech-savvy.

How can I use Wi-Fi when Ethernet is plugged in?

Go to Network and Internet settings in Windows, then Change Adapter settings. Select the wired connection, then edit its properties. Select Internet Protocol Version 4 (TCP/IPv4) and edit the properties. Select Use the following IP address and type in a static address.

Where is network cable plugged in?

Ethernet cables plug into Ethernet ports, which are larger than phone cable ports. An Ethernet port on a computer is accessible through the Ethernet card on the motherboard. This port is usually on the back of a desktop computer, or on the side of a laptop.

Why is my PC not detecting my Ethernet cable?

Try to connect to the same network on a different device. If you can connect, the source of the problem is likely due to your first PC. If you can't connect to the Ethernet network on either PC, it might be a problem with your router, internet service provider, or USB to Ethernet adapter.


1 Answers

You can use the GetIstNetworkAvailable-method to check if there is a network connection at all. Whenever it changes the NetworkAvailabilityChanged event get's fired. For more information see this question.

If you want to track the availability of different NetworkInterfaces here is an sample on how to do this.

like image 93
Carsten Avatar answered Oct 19 '22 00:10

Carsten