Evo kod iz jedan moj program a našao sam ga na nekom sajtu ne sećam se na kojem. Proverava dal' si konektovan na net.
Code:
#region Provera konekcije na internet
[DllImport("wininet.dll", CharSet = CharSet.Auto)]
static extern bool InternetGetConnectedState(ref ConnectionState lpdwFlags, int dwReserved);
[Flags]
enum ConnectionState : int
{
INTERNET_CONNECTION_MODEM = 0x01,
INTERNET_CONNECTION_LAN = 0x2,
INTERNET_CONNECTION_PROXY = 0x4,
INTERNET_RAS_INSTALLED = 0x10,
INTERNET_CONNECTION_OFFLINE = 0x20,
INTERNET_CONNECTION_CONFIGURED = 0x40
}
/// <summary>
/// Da li je računar konektovan na interent?
/// </summary>
/// <returns></returns>
public bool IsConnected()
{
ConnectionState conState = 0;
InternetGetConnectedState(ref conState, 0);
if ((conState & ConnectionState.INTERNET_CONNECTION_CONFIGURED) ==
ConnectionState.INTERNET_CONNECTION_CONFIGURED)
{
return true; //ukaži da jeste konektovan na internet
}
return false; //ukaži da nije konektovan
}
#endregion