You can try the function IsNetworkAlive with NETWORK_ALIVE_WAN flag
Here's some C# code
using System
using System.Runtime.InteropServices
namespace NetSens
/// <summary
/// Summary description for Class1
/// </summary
class Class
/// <summary
/// The main entry point for the application
/// </summary
[STAThread
static void Main(string[] args
int NETWORK_ALIVE_LAN = 0x00000001
int NETWORK_ALIVE_WAN = 0x00000002
int NETWORK_ALIVE_AOL = 0x00000004
if (IsNetworkAlive(ref NETWORK_ALIVE_WAN)
Console.WriteLine("Wan Alive")
if (IsNetworkAlive(ref NETWORK_ALIVE_LAN)
Console.WriteLine("Lan Alive")
if (IsNetworkAlive(ref NETWORK_ALIVE_AOL)
Console.WriteLine("Aol Alive")
string hostname = "
www.microsoft.com"
//for simplicity, we do not care about the QocInf
if (IsDestinationReachable(hostname,IntPtr.Zero)
Console.WriteLine("{0} is reachable",hostname)
els
Console.WriteLine("{0} is not reachable", hostname)
Console.Read()
[DllImport("sensapi.dll")
private extern static bool IsNetworkAlive(ref int flags)
[DllImport("sensapi.dll")
private extern static bool IsDestinationReachable(string dest,IntPtr ptr)
</code>