add ping and fix uptime

This commit is contained in:
LouisLam 2021-07-01 17:00:23 +08:00
parent 9c653c3d05
commit a6b5986dd6
9 changed files with 285 additions and 97 deletions

View file

@ -1,4 +1,5 @@
const tcpp = require('tcp-ping');
const Ping = require("./ping-lite");
exports.tcping = function (hostname, port) {
return new Promise((resolve, reject) => {
@ -20,3 +21,19 @@ exports.tcping = function (hostname, port) {
});
});
}
exports.ping = function (hostname) {
return new Promise((resolve, reject) => {
const ping = new Ping(hostname);
ping.send(function(err, ms) {
if (err) {
reject(err)
} else if (ms === null) {
reject(new Error("timeout"))
} else {
resolve(Math.round(ms))
}
});
});
}