Conexion a internet

¿En visual basic 6 como puedo comprobar el acceso a internet?

1 respuesta

Respuesta
1
Para verificar la conexion a internet puedes utilizar la API, fijate de colocar esto en un modulo:
Option Explicit
Public Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
Public Const INTERNET_CONNECTION_MODEM As Long = &H1
Public Const INTERNET_CONNECTION_LAN As Long = &H2
Public Const INTERNET_CONNECTION_PROXY As Long = &H4
Public Const INTERNET_CONNECTION_MODEM_BUSY As Long = &H8
Public Const INTERNET_RAS_INSTALLED As Long = &H10
Public Const INTERNET_CONNECTION_OFFLINE As Long = &H20
Public Const INTERNET_CONNECTION_CONFIGURED As Long = &H40
Public Function GetNetConnectString() As String
Dim dwflags As Long
Dim msg As String
If InternetGetConnectedState(dwflags, 0&) Then
If dwflags And INTERNET_CONNECTION_CONFIGURED Then
msg = msg & "network" & vbCrLf
End If
If dwflags And INTERNET_CONNECTION_LAN Then
msg = msg & "LAN"
End If
If dwflags And INTERNET_CONNECTION_PROXY Then
msg = msg & "proxy server. "
Else: msg = msg & "."
End If
If dwflags And INTERNET_CONNECTION_MODEM Then
msg = msg & "modem"
End If
If dwflags And INTERNET_CONNECTION_OFFLINE Then
msg = msg & "offline. "
End If
If dwflags And INTERNET_CONNECTION_MODEM_BUSY Then
msg = msg & "non-Internetconnection. "
End If
If dwflags And INTERNET_RAS_INSTALLED Then
msg = msg & "Remote Access Services"
End If
Else
msg = "No conectado a Internet"
End If
GetNetConnectString = "Conexion tipo: " & msg
End Function
ahora puedes desde tu programa llamar a la funcion de esta manera:
Conexion = GetNetConnectString()
Fijate que te va a entragar un string con el tipo de conexion que tenga la maquina, asi puedes ver no solo si existe conexion sino de que tipo es.
Esta muy bien esta funcion, pero si me
interesa saber si en ese instante tiene acceso a internet, porque puede que tenga configurado una conexion por LAN, pero no garantiza que en ese instante tenga el acceso a internet, no se si me explico?
Muchisimas gracias por tu tiempo, saludos !!!
Tienes razon en ese caso, si ya has echo una conexion a internet con la lan, esta ya queda marcada "Connected" ya que lo normal es tener habilitada el DHCP o con IP fijas, pero luego de verificar que ya esta configurada una conexion a internet activa, lo que podes hacer es una prueba de navegacion, para eso utilizamos nuevamente la API, agrega esto en las declaraciones del modulo:
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
Global ConexionOK As Boolean
ahora agrega esto entre las lineas de la rutina anterior
If InternetGetConnectedState(dwflags, 0&) Then
'agregado
If InternetCheckConnection("http://www.microsoft.com/", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
ConexionOK = False
Else
ConexionOK = True
End If
'continua lo anterior
If dwflags And INTERNET_CONNECTION_CONFIGURED Then
asi primero verifica la conexion, de lo contrario al intentar navegar se te puede abrir la ventana de conexion o discado a internet, luego de verificar que hay una conexion se hace un prueba de navegacion, asi te queda en la variable "ConexionOK" en verdader si se pudo conectar, fijate que puedes utilizar cuaquier pagina de internet, te he puesto la de Microsoft porque esa es casi imposible que en elgun momento este fuera de servicio.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas