Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
There are many ways to test connection of internet .

for example :
public bool WebRequestTest()
{
    string url = "http://www.google.com";
    try
    {
        System.Net.WebRequest myRequest = System.Net.WebRequest.Create(url);
        System.Net.WebResponse myResponse = myRequest.GetResponse();
        return true;
    }
    catch (System.Net.WebException)
    {
        return false;
    }
}


but I cant find a way for test Internet Access ! When Internet Access is not available this method return TRUE !!!

do you have any way (method) to test Internet Access ?@

many thanks ,,,
Posted

You do not check whether the response is valid.
Debug the response one time you are connected and one time while not connected. You will see then the difference.
 
Share this answer
 
v2
See CodeProject article: "How to use the Windows NLM API to get notified of new network connectivity" [^].

But, keep in mind that as the .NET FrameWork has evolved, so has its facilities for access to the state of network/internet-connections changed: [^].

You should evaluate any possible changes, or other methods, in Win >= 8 [^].

Also, consider Eric Lippert's comment: "Also, note that there is no way to check if the user is connected to the internet; all you can tell is if they were connected in the past. Suppose you had a method: "bool c = IsConnected(); if (c) { DoSomething(); } " -- between the call to IsConnected and DoSomething, the wireless network router might have been unplugged. IsConnected really should be called WasRecentlyConnected. – Eric Lippert Jan 9 '10 at 15:47" ... on a StackOverFlow thread: [^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900