IE's sensapi.dll IsNetworkAlive() ?
A coworker pointed me to this post by Ying-Shen Yu [MSFT].
I decided to copy his comment in full, just incase google drops it or you dont feel like hitting that link above.
----
In my further research, both APIs have their limitations(e.g. IsDestinationReachable depends on if the server would respond to Ping), so if you have problem in using these APIs, maybe you can try using TcpClient class and connecting to that web service first to see if the service is available, when your application starting up.
----
I also grabbed his code and created a handly little class.
----
(create a new C# Class library)
using System;
using System.Runtime.InteropServices;
namespace Sense {
public class API {
private static int NETWORK_ALIVE_LAN = 0x00000001;
private static int NETWORK_ALIVE_WAN = 0x00000002;
private static int NETWORK_ALIVE_AOL = 0x00000004;
public static bool IsLanAlive() {
return IsNetworkAlive(ref NETWORK_ALIVE_LAN);
}
public static bool IsWanAlive() {
return IsNetworkAlive(ref NETWORK_ALIVE_WAN);
}
public static bool IsAOLAlive() {
return IsNetworkAlive(ref NETWORK_ALIVE_AOL);
}
public static bool IsDestinationAlive(string Destination) {
return (IsDestinationReachable(Destination,IntPtr.Zero));
}
[DllImport("sensapi.dll")]
private extern static bool IsNetworkAlive(ref int flags);
[DllImport("sensapi.dll")]
private extern static bool IsDestinationReachable(string dest,IntPtr ptr);
}
}
----
And finally useage (create a new Console app):
while(true) {
Console.WriteLine("Lan:"+Sense.API.IsLanAlive());
Console.WriteLine("Wan:"+Sense.API.IsWanAlive());
Console.WriteLine("Aol:"+Sense.API.IsAOLAlive());
Console.WriteLine("Sip:"+Sense.API.IsDestinationAlive("www.microsoft.com"));
System.Threading.Thread.Sleep(1000);
}
Let it run for a few seconds and then yank your network cable.
EDIT:
Found the related docs on MSDN.