How to check for a network connection in .NET 2.0 (C# or VB)

To check for a network connection in .NET 2.0 use this:


To monitor a change in IP address or a change in network availability, use the events from the NetworkChange class:



17 thoughts on “How to check for a network connection in .NET 2.0 (C# or VB)

  1. There’s a MIX video on how to do this in Silverlight. The same APIs work in .NET as well. One of the key bits is that you’re only connected to the internet if you’ve made a connection to your server and have verified the response — otherwise you might just connected to a local web page asking you for $9.95 to connect for a day 🙂

  2. I’m facing a bit problem using ‘NetworkAvailabilityChanged’. If I’m connected through multiple interfaces at a time then I didn’t get ‘NetworkAvailabilityChanged’ event fired. But if I’m using single connection then this event fires. Could you please suggest a solution.

  3. Hi Zeus, if you have multiple network connections you’ll only receive the NetworkAvailabilityChanged event when all connections are disconnected and when 1 connection is re-established. The line below is taken from the MSDN documentation for this event.

    The NetworkChange class raises NetworkAvailabilityChanged events when the availability of the network changes. The network is available when at least one network interface is marked “up” and is not a tunnel or loopback interface.

  4. The NetworkAvailabilityChanged event doesn’t appear to get raised when a ‘Dial-Up Connection’ is disconnected. (It does when the dial-up connection is made though). It may be model/driver specific – I’ve only tried it on a ZTE GSM modem.

Comments are closed.