1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
<script type='text/javascript'>
window.onload=function(){
function ping(ip, callback) {
if (!this.inUse) {
this.status = 'unchecked';
this.inUse = true;
this.callback = callback;
this.ip = ip;
var _that = this;
this.img = new Image();
this.img.onload = function () {
_that.inUse = false;
_that.callback('Connection_OK');
};
this.img.onerror = function (e) {
if (_that.inUse) {
_that.inUse = false;
_that.callback('Connection_OK', e);
}
};
this.start = new Date().getTime();
this.img.src = "http://" + ip;
this.timer = setTimeout(function () {
if (_that.inUse) {
_that.inUse = false;
_that.callback('Hors_ligne');
}
}, 1500);
}
}
var PingModel = function (servers) {
var self = this;
var myServers = [];
ko.utils.arrayForEach(servers, function (location) {
myServers.push({
name: location,
status: ko.observable('unchecked')
});
});
self.servers = ko.observableArray(myServers);
ko.utils.arrayForEach(self.servers(), function (s) {
s.status('checking');
new ping(s.name, function (status, e) {
s.status(status);
});
});
};
var komodel = new PingModel([
'localhost',
'10.252.0.28',
'10.252.0.29',
'10.252.0.38',
'10.252.0.39',
'10.252.0.41',
'10.252.0.225',
'10.252.0.42',
'10.252.0.44',
'10.252.0.46',
'10.252.0.49',
'10.252.0.220',
'10.252.0.50',
'10.252.0.227',
'10.252.0.33',
'10.252.0.226',
'10.252.0.48',
'10.252.0.35',
'10.252.0.223',
'10.252.0.34',
'10.252.0.47',
'10.252.0.45',
'10.252.0.43',
'10.252.0.37',
'10.252.0.224',
'10.252.0.36',
'10.252.0.51',
'10.252.0.52',
'10.201.140.1',
'10.201.140.2',
'10.201.140.3',
'10.201.166.1',
'10.201.166.2',
'10.201.166.4',
'10.201.166.3',
'10.201.166.5',
'10.201.133.1',
'10.201.133.50',
'10.201.133.51'
]);
ko.applyBindings(komodel);
}//]]>
</script> |
Partager