-
InternetGetConnectedState 로 인터넷 연결 체크dev/.NET 2009. 2. 11. 14:38http://msdn.microsoft.com/en-us/library/aa384702(VS.85).aspx
using System;
using System.Runtime.InteropServices;
using System.Text;namespace ClassLibrary5
{
class __InetAvailable
{
//HOW TO: determine whether or not there is a connection to the
// Internet present on the local machine.[DllImport("WININET", CharSet = CharSet.Auto)]
static extern bool InternetGetConnectedState(
ref InternetConnectionState lpdwFlags,
int dwReserved);[Flags]
enum InternetConnectionState : int
{
INTERNET_CONNECTION_MODEM = 0x1,
INTERNET_CONNECTION_LAN = 0x2,
INTERNET_CONNECTION_PROXY = 0x4,
INTERNET_RAS_INSTALLED = 0x10,
INTERNET_CONNECTION_OFFLINE = 0x20,
INTERNET_CONNECTION_CONFIGURED = 0x40
}static void Main()
{
InternetConnectionState flags = 0;Console.WriteLine(
"InternetGetConnectedState : {0} - {1}",
(InternetGetConnectedState(ref flags, 0) ? "ONLINE" : "OFFLINE"),
flags
);
}
}
}