Hello guys,
It my frist topic in this forum so i hopeI hope you like it??

In this topic we w'll learn how to check internet connection using a simple code.
frist make a new project And add a label and timer .
second Double click on timer to type code .

bool con = Networkinterface.GetIsNetworkAvailable();
if (con == true(
{
lable1.text="your are connect";
}
else
{
label1.text="you are not connected";
}

You can watch the explanation from hereClick Here

Naheedmir commented: Thank you for this information... It is really going to help me for my project +0

Recommended Answers

All 3 Replies

In this topic we w'll learn how to check internet connection using a simple code.

This code checks if there is a network connection available, and will most likely ALWAYS return TRUE.

Detecting if there is an internet connection is better suited with System.Net.Dns.GetHostEntry(). The only problem you have then, is when the website you are trying to reach is down.

Do you have any possible excuse for coding
if (con == true ...
instead of
if (con ...

For you to check for network connection, you can make use of the System.Net.NetworkInformation. See the below

    if(System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
     Label1.Text = "There is active network"

            }
            else
            {
            Label1.Text = "No network detected";

            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.