|
|
@ -45,15 +45,30 @@ exports.tcping = function (hostname, port) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
exports.ping = function (hostname) {
|
|
|
|
exports.ping = async (hostname) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
await exports.pingAsync(hostname);
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
// If the host cannot be resolved, try again with ipv6
|
|
|
|
|
|
|
|
if (e.message.includes("service not known")) {
|
|
|
|
|
|
|
|
await exports.pingAsync(hostname, true);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
throw e;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.pingAsync = function (hostname, ipv6 = false) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const ping = new Ping(hostname);
|
|
|
|
const ping = new Ping(hostname, {
|
|
|
|
|
|
|
|
ipv6
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
ping.send(function (err, ms) {
|
|
|
|
ping.send(function (err, ms, stdout) {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
reject(err)
|
|
|
|
reject(err);
|
|
|
|
} else if (ms === null) {
|
|
|
|
} else if (ms === null) {
|
|
|
|
reject(new Error("timeout"))
|
|
|
|
reject(new Error(stdout))
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
resolve(Math.round(ms))
|
|
|
|
resolve(Math.round(ms))
|
|
|
|
}
|
|
|
|
}
|
|
|
|