Skip to content

Instantly share code, notes, and snippets.

@roshanca
Created August 1, 2013 01:58
Show Gist options
  • Save roshanca/6127845 to your computer and use it in GitHub Desktop.
Save roshanca/6127845 to your computer and use it in GitHub Desktop.
use to test ping.
function ping(ip) {
var img = new Image();
var start = new Date().getTime();
img.src = 'http://' + ip + '?t=' + start;
var flag = false;
img.onload = function () {
flag = true;
console.log('ok');
}
img.onerror = function () {
flag = true;
console.log('ok');
}
var timer = setTimeout(function () {
if (!flag) {
flag = false;
console.log('failed');
}
}, 1500);
}
ping('192.168.1.1');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment