Click here to Skip to main content
15,561,246 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Dear all,
I want to develop an application that check internet connection available in PC while pressing a button.

Please help me soon.


Regards,
Md. Shawon Mahmud
Posted
Comments
Fardan 12-Feb-12 6:49am    
Ok, What's the question?

Hello:

Easy way:

C#
try
 {
    System.Net.IPHostEntry iPHostEntry = System.Net.Dns.GetHostEntry("www.codeproject.com");
 }
 catch
 {
    Console.WriteLine("No connection...");
 }


Recommended way:

http://msdn.microsoft.com/en-us/library/aa384702%28VS.85%29.aspx[^]
 
Share this answer
 
v3
Comments
Sean A. Hanley 12-Feb-12 9:38am    
The InternetGetConnectedState method is good, but since it only determines if there is some kind of LAN connection, I like to follow-up with InternetCheckConnection and pass in a URL to something I know will confirm they can actually connect to an external server.
zyck 12-Feb-12 9:53am    
nice solution!
Try This
C#
using System.Net.NetworkInformation;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {

        }
        private void button1_Click(object sender, EventArgs e)
        {
            NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged);
        }
        public void NetworkChange_NetworkAvailabilityChanged(Object sender, NetworkAvailabilityEventArgs e)
        {
            if (e.IsAvailable)
                MessageBox.Show("Connected");
            else
                MessageBox.Show("Disconnected");
        }
    }
}
 
Share this answer
 
from msdn :

http://msdn.microsoft.com/en-us/library/aa384702%28VS.85%29.aspx
 
Share this answer
 
Please let us know what you have tried. What have you started to implemented already? What are you current stuck on doing.

Asking questions in this manner, will be taken by some as us doing your course work.

Search providers - such as google and bing will help you get started.
 
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