I want to check internet connectivity within a program. For example I want
the program to ping microsoft.com and to determine that there is a connection
according to ping responses.
How can I do that?
> I want to check internet connectivity within a program. For example I
> want
[quoted text clipped - 3 lines]
>
> How can I do that?
Did you look at the Ping class? (in System.Net.NetworkInformation)
basulasz - 09 Jan 2008 18:48 GMT
No. Actually I haven't known about anything about that class. I am new in
.net, and haven't used this namespace before
> > I want to check internet connectivity within a program. For example I
> > want
[quoted text clipped - 5 lines]
>
> Did you look at the Ping class? (in System.Net.NetworkInformation)
If you want a general API, IsInternetConnected will do it:
http://msdn2.microsoft.com/en-us/library/aa366143(VS.85).aspx
but for a specific site you'd need another test, like ping.
What are you trying to do? For example a ping to a specific location will
tell you about a physical connection, but opening a browser window to it can
fail if IE has phishing or security blocking of that site.

Signature
Phil Wilson
[MVP Windows Installer]
>I want to check internet connectivity within a program. For example I want
> the program to ping microsoft.com and to determine that there is a
> connection
> according to ping responses.
>
> How can I do that?
basulasz - 10 Jan 2008 21:12 GMT
I have a Windows service application which uses a web service to send SMS
messages to cell phones, and it requires an available internet connection, so
i need to ping a specific location, and I think ping class in .NET will be
helpful for this purpose.
Thanks a lot...
> If you want a general API, IsInternetConnected will do it:
> http://msdn2.microsoft.com/en-us/library/aa366143(VS.85).aspx
[quoted text clipped - 9 lines]
> >
> > How can I do that?
I hacked up this little helper class that will allow you to check if you're
connected to the internet without having to ping a specific site. The
method you need to call is NetUtils.IsConnectedToInternet().
/// <summary>
/// A collection of network related methods.
/// </summary>
public class NetUtils
{
/////////////////////
// Imported functions
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState
(out int nDescription,
int nReserved);
/////////////
// Operations
/// <summary>
/// Checks if a connection to the internet exists.
/// </summary>
/// <returns>true if a connection to the internet exists.</returns>
public static bool IsConnectedToInternet()
{
int nDesc = 0;
if (!InternetGetConnectedState (out nDesc, 0))
return (false);
return (true);
}
}
Cheers,
/ravi
------------------------------------------------------------------------
>I want to check internet connectivity within a program. For example I want
> the program to ping microsoft.com and to determine that there is a
> connection
> according to ping responses.
>
> How can I do that?