If what you want is to check the state of the internet in .Net
without depending on WebClient
class or Google
, this is the best way
First, import the DLL wininet
[System.Runtime.InteropServices.DllImport("wininet.dll")]
Then, call the static extern bool InternetGetConnectedState(...)
This returns true
if the internet connects and false
if it can not connect, regardless of Google
:
[System.Runtime.InteropServices.DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
public static bool IsConnected()
{
return InternetGetConnectedState(out int description, 0);
}
Where:
if(IsConnected())
{
//Internet is connected
}
else
{
//Internet is not connected
}