[VB.NET] Verificar conexión a internet

Iniciado por Bloc, Agosto 13, 2013, 08:08:04 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Agosto 13, 2013, 08:08:04 PM Ultima modificación: Mayo 27, 2014, 09:56:51 PM por Expermicid
Código: vbnet
    Function Verificar_conexion_a_internet()

        'Nombre: Verificar conexión a internet
        'Autor: Bloc
        'Fecha Publicada: 13/08/2013

        If My.Computer.Network.IsAvailable = True Then
            Try
                If My.Computer.Network.Ping("www.google.com", 10) Then
                    MsgBox("Si hay conexión a internet", MsgBoxStyle.Information)
                End If
            Catch ex As Exception
                MsgBox("No hay conexión a internet", MsgBoxStyle.Critical)
            End Try
        End If
    End Function


Saludos!.
Skype: Bloc-Hack

El codigo no funciona... inhabilite el DNS de mi red y al ejecutar me dice que no hay conexion de internet. pero hago ping a 8.8.4.4 y veo que si tengo conexion a internet.

You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
El codigo no funciona... inhabilite el DNS de mi red y al ejecutar me dice que no hay conexion de internet. pero hago ping a 8.8.4.4 y veo que si tengo conexion a internet.

Jojojoo, muy buen detalle el aportado por [L]ord [R]NA, ademas tiene esa sutileza que me encanta!

Querido Bloc, es cierto que si no tienes DNS que resuelva un domino tu programa fallará. Por tanto reemplaza esta linea:

Código: vbnet
If My.Computer.Network.Ping("www.google.com", 10) Then 


Por esta otra:

Código: vbnet
If My.Computer.Network.Ping("8.8.8.8", 10) Then 


Saludos!


Agosto 21, 2013, 11:19:48 PM #3 Ultima modificación: Agosto 21, 2013, 11:24:46 PM por [L]ord [R]NA
Código: c#

private void Test_Connection()
{
    System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
    System.Net.NetworkInformation.PingReply reply = ping.Send("1.1.1.1");
    MessageBox.Show(reply.Status.ToString()!="Success"?
                    "No se tiene conexion a Internet":
                    "Se tiene conexion a Internet");           
        }