Test for Internet Connection


/ Published in: VB.NET
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. Public Function GotInternet() As Boolean
  2. Dim req As System.Net.HttpWebRequest
  3. Dim res As System.Net.HttpWebResponse
  4. GotInternet = False
  5. Try
  6. req = CType(System.Net.HttpWebRequest.Create("http://www.google.com"), System.Net.HttpWebRequest)
  7. res = CType(req.GetResponse(), System.Net.HttpWebResponse)
  8. req.Abort()
  9. If res.StatusCode = System.Net.HttpStatusCode.OK Then
  10. GotInternet = True
  11. End If
  12. Catch weberrt As System.Net.WebException
  13. GotInternet = False
  14. Catch except As Exception
  15. GotInternet = False
  16. End Try
  17. End Function

URL: http://forums.devbuzz.com/tm.asp?m=15988&p=1&tmode=1

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.