elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Curso de javascript por TickTack


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Funcion en javascript adaptarlo a VB.NEt !
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Funcion en javascript adaptarlo a VB.NEt !  (Leído 2,638 veces)
TrashAmbishion


Desconectado Desconectado

Mensajes: 756


Ver Perfil
Funcion en javascript adaptarlo a VB.NEt !
« en: 4 Julio 2020, 04:14 am »

Hola,

El siguiente codigo lo que hace es medir la velocidad de subida y descarga (SpeedTest) quisiera adaptarlo a Vb.Net de ser posible o me sugieren ejecutarlo directo desde la Web

Código
  1. //INITIALIZE SPEEDTEST
  2. var s=new Speedtest(); //create speedtest object
  3. s.setParameter("telemetry_level","basic"); //enable telemetry
  4.  
  5. var meterBk=/Trident.*rv:(\d+\.\d+)/i.test(navigator.userAgent)?"#EAEAEA":"#80808040";
  6. var dlColor="#6060AA",
  7. ulColor="#616161";
  8. var progColor=meterBk;
  9.  
  10. //CODE FOR GAUGES
  11. function drawMeter(c,amount,bk,fg,progress,prog){
  12. var ctx=c.getContext("2d");
  13. var dp=window.devicePixelRatio||1;
  14. var cw=c.clientWidth*dp, ch=c.clientHeight*dp;
  15. var sizScale=ch*0.0055;
  16. if(c.width==cw&&c.height==ch){
  17. ctx.clearRect(0,0,cw,ch);
  18. }else{
  19. c.width=cw;
  20. c.height=ch;
  21. }
  22. ctx.beginPath();
  23. ctx.strokeStyle=bk;
  24. ctx.lineWidth=12*sizScale;
  25. ctx.arc(c.width/2,c.height-58*sizScale,c.height/1.8-ctx.lineWidth,-Math.PI*1.1,Math.PI*0.1);
  26. ctx.stroke();
  27. ctx.beginPath();
  28. ctx.strokeStyle=fg;
  29. ctx.lineWidth=12*sizScale;
  30. ctx.arc(c.width/2,c.height-58*sizScale,c.height/1.8-ctx.lineWidth,-Math.PI*1.1,amount*Math.PI*1.2-Math.PI*1.1);
  31. ctx.stroke();
  32. if(typeof progress !== "undefined"){
  33. ctx.fillStyle=prog;
  34. ctx.fillRect(c.width*0.3,c.height-16*sizScale,c.width*0.4*progress,4*sizScale);
  35. }
  36. }
  37. function mbpsToAmount(s){
  38. return 1-(1/(Math.pow(1.3,Math.sqrt(s))));
  39. }
  40. function format(d){
  41.    d=Number(d);
  42.    if(d<10) return d.toFixed(2);
  43.    if(d<100) return d.toFixed(1);
  44.    return d.toFixed(0);
  45. }
  46.  
  47. //UI CODE
  48. var uiData=null;
  49. function startStop(){
  50.    if(s.getState()==3){
  51. //speedtest is running, abort
  52. s.abort();
  53. data=null;
  54. I("startStopBtn").className="";
  55. initUI();
  56. }else{
  57. //test is not running, begin
  58. I("startStopBtn").className="running";
  59. I("shareArea").style.display="none";
  60. s.onupdate=function(data){
  61.            uiData=data;
  62. };
  63. s.onend=function(aborted){
  64.            I("startStopBtn").className="";
  65.            updateUI(true);
  66.            if(!aborted){
  67.                //if testId is present, show sharing panel, otherwise do nothing
  68.                try{
  69.                    var testId=uiData.testId;
  70.                    if(testId!=null){
  71.                        var shareURL=window.location.href.substring(0,window.location.href.lastIndexOf("/"))+"/results/?id="+testId;
  72.                        I("resultsImg").src=shareURL;
  73.                        I("resultsURL").value=shareURL;
  74.                        I("testId").innerHTML=testId;
  75.                        I("shareArea").style.display="";
  76.                    }
  77.                }catch(e){}
  78.            }
  79. };
  80. s.start();
  81. }
  82. }
  83. //this function reads the data sent back by the test and updates the UI
  84. function updateUI(forced){
  85. if(!forced&&s.getState()!=3) return;
  86. if(uiData==null) return;
  87. var status=uiData.testState;
  88. I("ip").textContent=uiData.clientIp;
  89. I("dlText").textContent=(status==1&&uiData.dlStatus==0)?"...":format(uiData.dlStatus);
  90. drawMeter(I("dlMeter"),mbpsToAmount(Number(uiData.dlStatus*(status==1?oscillate():1))),meterBk,dlColor,Number(uiData.dlProgress),progColor);
  91. I("ulText").textContent=(status==3&&uiData.ulStatus==0)?"...":format(uiData.ulStatus);
  92. drawMeter(I("ulMeter"),mbpsToAmount(Number(uiData.ulStatus*(status==3?oscillate():1))),meterBk,ulColor,Number(uiData.ulProgress),progColor);
  93. I("pingText").textContent=format(uiData.pingStatus);
  94. I("jitText").textContent=format(uiData.jitterStatus);
  95. }
  96. function oscillate(){
  97. return 1+0.02*Math.sin(Date.now()/100);
  98. }
  99. //update the UI every frame
  100. window.requestAnimationFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||(function(callback,element){setTimeout(callback,1000/60);});
  101. function frame(){
  102. requestAnimationFrame(frame);
  103. updateUI();
  104. }
  105. frame(); //start frame loop
  106. //function to (re)initialize UI
  107. function initUI(){
  108. drawMeter(I("dlMeter"),0,meterBk,dlColor,0);
  109. drawMeter(I("ulMeter"),0,meterBk,ulColor,0);
  110. I("dlText").textContent="";
  111. I("ulText").textContent="";
  112. I("pingText").textContent="";
  113. I("jitText").textContent="";
  114. I("ip").textContent="";
  115. }
  116. </script>
  117.  

Si quieren subo el sitio completo.. es bien simple..

Saludos y gracias cualquier sugerencia..


En línea

ThunderCls


Desconectado Desconectado

Mensajes: 455


Coder | Reverser | Gamer


Ver Perfil WWW
Re: Funcion en javascript adaptarlo a VB.NEt !
« Respuesta #1 en: 17 Julio 2020, 14:45 pm »

El codigo que pones solo esta manipulando la UI, nada de test de velocidad. Los ficheros que debes mirar son speedtest.js y speedtest_worker.js, pero en fin, si lo que quieres es hacer un test de velocidad (cualquier lenguaje), solo tienes que descargar algun fichero de un servidor en internet y hacer algunos calculos para determinar cuanto tiempo toma. Conociendo el tamaño del fichero y el tiempo que tomo la descarga puedes calcular la velocidad de tu conexion. Lo mismo aplica para la velocidad de subida.
Saludos


En línea

-[ "…I can only show you the door. You're the one that has to walk through it." – Morpheus (The Matrix) ]-
http://reversec0de.wordpress.com
https://github.com/ThunderCls/
TrashAmbishion


Desconectado Desconectado

Mensajes: 756


Ver Perfil
Re: Funcion en javascript adaptarlo a VB.NEt !
« Respuesta #2 en: 16 Agosto 2020, 20:18 pm »

El codigo que pones solo esta manipulando la UI, nada de test de velocidad. Los ficheros que debes mirar son speedtest.js y speedtest_worker.js, pero en fin, si lo que quieres es hacer un test de velocidad (cualquier lenguaje), solo tienes que descargar algun fichero de un servidor en internet y hacer algunos calculos para determinar cuanto tiempo toma. Conociendo el tamaño del fichero y el tiempo que tomo la descarga puedes calcular la velocidad de tu conexion. Lo mismo aplica para la velocidad de subida.
Saludos

Gracias lo veré
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
funcion javascript
Desarrollo Web
qiqeroot 2 2,279 Último mensaje 5 Diciembre 2010, 19:11 pm
por Nakp
[javascript] llamar a funcion que se recibe por parametro de la funcion
Desarrollo Web
Graphixx 0 5,617 Último mensaje 24 Abril 2012, 19:36 pm
por Graphixx
Pasar funcion PHP a javascript
Desarrollo Web
blaknez root 1 1,566 Último mensaje 27 Julio 2014, 18:41 pm
por MinusFour
AYUDA CON FUNCION javascript
Desarrollo Web
Christopher Bryan 1 1,715 Último mensaje 11 Agosto 2014, 18:32 pm
por MinusFour
Una función en javascript
Desarrollo Web
Ali Baba 3 2,538 Último mensaje 18 Mayo 2017, 21:20 pm
por dato000
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines