Testing Internet connection?

S

sprungli

In a Library or Win Forms application how can my code test whether the
computer is connected to the Internet? (The computer could use a dial-up
connection or it could be on a network.)

TIA
 
S

Sijin Joseph

There are two ways you can do that, one is to simply try and make a web
request to a known url and catch the exception that would occur when
there is no internet connection, this method is detailed here

http://www.code101.com/Code101/DisplayArticle.aspx?cid=77

and here

http://www.developerfusion.com/show/3903/

secondly, you can use the InternetGetConnectedState() API from
WinInet.dll, this method is detailed here

http://www.vbip.com/wininet/wininet_dialup.asp

and here

http://vbnet.mvps.org/index.html?code/network/internetgetconnectedstate.htm

Hope that helps.


Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top