Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I need to understand whether my dial-up connection is connected or is not connected.
I have used this dll and code, but sometimes it doesn't give me correct answer:
any other solutions will be appreciated, tnx

C#
[DllImport("wininet.dll")]
       private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);

public static bool IsConnected()
       {
           try
           {
               int ConnDesc;
               return InternetGetConnectedState(out ConnDesc, 0);
           }
           catch
           {
               return false;
           }
       }
Posted
Updated 20-Aug-13 0:04am
v2

Try Pinging to a remote webserver ie, google.com and collect the reply...

http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping.aspx[^]
 
Share this answer
 
C#
using OpenNETCF.Net.NetworkInformation;

            bool result = false;

            Ping ping = new Ping();

            PingReply pingReply = ping.Send("www.google.com");

            if (pingReply.Status == IPStatus.Success)
                result = true;
 
Share this answer
 
v2

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