Re: A ping program in javascript?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: A ping program in javascript?

From: Csaba Gabor <Csaba@z6.com>
Date: Wed Jul 20 2005 - 19:51:48 CEST

How about something like this for javascript ping times:

<body onload="alert('body loaded');
              window.startTime=new Date();
              var imgSrc='http://us.i1.yimg.com/us.yimg.com'+
                         '/i/us/nt/hdr/stw.gif'+
                         '?cacheBuster='+Math.random();
              document.getElementById('myPingTest').src=imgSrc">
<IMG id=myPingTest
     onload="var endTime=new Date();
             alert('ping time in milliseconds: '+
             (endTime.getMilliseconds()-
              window.startTime.getMilliseconds()))">
</body>

It assumes a cooperating server, of course, plus there is additional
delay due to server processing. Still... it may give you a rough
idea. As implied by the "cacheBuster" (which line is there solely to
prevent browser cacheing), I would be very wary of cacheing effects
both of the image and the path taken to the server.

Csaba Gabor from Vienna

Egil Hansen wrote:
> Hi
>
> I'm wondering if its possible to write a javascript, that can ping a ip
> and return the average round trip time (like ping in dos/linux)?
>
> Regards, Egil.
Received on Tue Oct 18 02:58:50 2005