I found this piece of code on the internet, the author of this code is Tamer Oz.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace Coderbuddy
{
public class CheckInternetConnection
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
public bool IsInternetConnectionAvailable()
{
int Desc;
return InternetGetConnectedState(out Desc, 0);
}
}
}