میتونی این کد رو استفاده کنی البته راههای دیگری هم داره
Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, ByVal dwNameLen As Integer, ByVal dwReserved As Long) As Long
Dim sConnType As String * 255
Private Sub Form_Load()
Dim Ret As Long
Ret = InternetGetConnectedStateEx(Ret, sConnType, 254, 0)
If Ret = 1 Then
MsgBox "You are connected to Internet via a " & sConnType, vbInformation
Else
MsgBox "You are not connected to internet", vbInformation
End If
End Sub
یا راه دیگه :
Private Const FLAG_ICC_FORCE_CONNECTION = &H1
Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Private Sub Form_Load()
If InternetCheckConnection("http://www.barnamenevis.org/", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
MsgBox "Connection to http://www.barnamenevis.org/ failed!", vbInformation
Else
MsgBox "Connection to http://www.barnamenevis.org/ succeeded!", vbInformation
End If
End Sub