/ Published in: VB.NET
URL: http://forums.devbuzz.com/tm.asp?m=15988&p=1&tmode=1
This is a simple function to test for an internet connection. Originally grabbed from "devbuzz" at the devbuzz forums (see link) and now modified for VB.NET 3.5
Expand |
Embed | Plain Text
Public Function GotInternet() As Boolean Dim req As System.Net.HttpWebRequest Dim res As System.Net.HttpWebResponse GotInternet = False Try req = CType(System.Net.HttpWebRequest.Create("http://www.google.com"), System.Net.HttpWebRequest) res = CType(req.GetResponse(), System.Net.HttpWebResponse) req.Abort() If res.StatusCode = System.Net.HttpStatusCode.OK Then GotInternet = True End If Catch weberrt As System.Net.WebException GotInternet = False Catch except As Exception GotInternet = False End Try End Function
Comments
Subscribe to comments
You need to login to post a comment.

HttpWebRequest takes to long to test the connection. If you are already accessing a web service, then it is easier and quicker to attempt to connect to the web service for an internet connectivity check..
source : http://net-informations.com/vbprj/communications/internet-connection.htm