Speed Test: una pequeña Aplicación VBS para medir velocidad de internet

Este es un ejemplo de una aplicación VBS para realizar mediciones de velocidad (speed test) de una conexión a internet. Es una aplicación VBS que corre directamente en Windows bajo la extensión .vbs o convirtiéndola en un ejecutable como .exe.

Velocidad de Internet o Speed Test
Aplicación VBS para Speed Test o Velocidad de Internet

Esta aplicación para speed test necesita de un sitio ftp a donde podremos subir y bajar un archivo con un tamaño determinado. En este ejemplo el sitio ftp tiene dirección xxx.xxx.xxx.xxx, usuario user y contraseña clave

Const ForWriting = 2

Dim objOutStream, objjFSO, objShell
Dim size,StartTime,EndTime,Lapse
Dim fso
Dim c ' File contents (Array)
Dim i ' Loop counter
Dim p ' Position of search string
Dim s ' Search String
dim r


Set objShell = CreateObject("WScript.Shell")

objShell.Run "%comspec% /c del empty*", 0, true
objShell.Run "%comspec% /c del result_*", 0, true
objShell.Run "%comspec% /c del test_file*", 0, true

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutStream = objFSO.OpenTextFile("empty.txt", ForWriting, True)
With objOutStream
    .WriteLine "USER user"   ' USERNAME
    .WriteLine "clave"     ' Password
    .WriteLine "binary"
    .WriteLine "get test_file2M"    ' Get all files with today's date in it
    .WriteLine "quit"
    .Close
End With

retorno=objShell.Run ("%comspec% /c FTP -n -i -s:" & "empty.txt" & " " & "xxx.xxx.xxx.xxx > result_down.txt", 0, True)

s = "ftp:"

Set fso = CreateObject("Scripting.FileSystemObject")

c = Split(fso.OpenTextFile("result_down.txt", 1, False).ReadAll, vbCrLf)

For i = 0 To UBound(c)
p = InStr(1, c(i), s, vbTextCompare)
If p > 0 Then
r=Split(c(i)," ")
speed1= left(r(6),len(r(6))-1)
speed1= Replace(speed1,".",",")
End If
Next

Set fso = Nothing
Set c= nothing

Set objFSO1 = CreateObject("Scripting.FileSystemObject")
Set objOutStream1 = objFSO.OpenTextFile("empty1.txt", ForWriting, True)

With objOutStream1
    .WriteLine "USER user"   ' USERNAME
    .WriteLine "clave"     ' Password
    .WriteLine "binary"
    .WriteLine "put test_file_up"    ' Get all files with today's date in it
    .WriteLine "quit"
    .Close
End With

Set objShell1 = CreateObject("WScript.Shell")
objShell1.Run "%comspec% /c fsutil file createnew test_file_up 2097152", 0, true
retorno=objShell1.Run ("%comspec% /c FTP -n -i -s:" & "empty1.txt" & " " & "xxx.xxx.xxx.xxx > result_up.txt", 0, true)

Set fso = CreateObject("Scripting.FileSystemObject")

c = Split(fso.OpenTextFile("result_up.txt", 1, False).ReadAll, vbCrLf)

For i = 0 To UBound(c)
p = InStr(1, c(i), s, vbTextCompare)
If p > 0 Then
r=Split(c(i)," ")
speed2= left(r(6),len(r(6))-1)
speed2= Replace(speed2,".",",")
End If
Next

mensaje1="Velocidad de bajada: " & formatnumber(speed1*8/1024,2) & " Mbps" & vbCrLf
mensaje2="Velocidad de subida: " & formatnumber(speed2*8/1024,2) & " Mbps "
MsgBox  mensaje1 & mensaje2 ,4096,"Prueba de Velocidad ITSoftware SAS"

objShell.Run "%comspec% /c del empty*", 0, true
objShell.Run "%comspec% /c del result_*", 0, true
objShell.Run "%comspec% /c del test_file*", 0, true

La función de ese programa es descargar el archivo test_file2M del sitio ftp, tomar los resultados de la medición de velocidad de la transferencia, luego crear otro archivo de 2MB llamado test_file_up, subirlo al sitio ftp y finalmente tomar los resultados de esta segunda medida, que se han guardado en un archivo de texto.

Una vez tomados estos valores, ya tenemos los valores de upload y download (subida y bajada), para mostrarlos o guardarlos en un archivo o base de datos.

Este es un servicio de divulgación de conocimiento de ITSoftware SAS.

Si te ha gustado este artículo, por favor no te olvides de compartirlo en las redes sociales.  Thks  🙂

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.