codice:
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
Questo è il modo semplice ed efficace che consiste nel fare un ping a un sito e valutarne la risposta. C'era poi un modo per verificarlo tramite le api di windows, ma purtroppo non lo trovo più... con una ricerca non dovrebbe essere difficile trovarlo.