[C#]使用InternetGetConnectedState API偵測目前電腦網路的連線狀態
namespace ConsoleApplication21 { class Program { [DllImport(“wininet”)] public static extern bool InternetGetConnectedState( ref uint lpdwFlags, uint dwReserved );
static void Main(string[] args)
{
uint flags = 0x0;
var isNetworkAvailable = InternetGetConnectedState(ref flags, 0);
Console.WriteLine(string.Format("Network available: {0} ({1})", isNetworkAvailable.ToString(), flags.ToString()));
}
}
}