0
0
mirror of https://github.com/louislam/uptime-kuma.git synced 2024-11-22 11:47:30 +01:00

add -6 to ping cmd if ipv6 address

This commit is contained in:
LouisLam 2021-08-10 20:39:58 +08:00
parent f089bf73c3
commit 2a4695a774

View File

@ -1,7 +1,7 @@
// https://github.com/ben-bradley/ping-lite/blob/master/ping-lite.js
// Fixed on Windows
let spawn = require("child_process").spawn,
const net = require("net");
const spawn = require("child_process").spawn,
events = require("events"),
fs = require("fs"),
WIN = /^win/.test(process.platform),
@ -24,14 +24,24 @@ function Ping(host, options) {
this._bin = "c:/windows/system32/ping.exe";
this._args = (options.args) ? options.args : [ "-n", "1", "-w", "5000", host ];
this._regmatch = /[><=]([0-9.]+?)ms/;
} else if (LIN) {
this._bin = "/bin/ping";
this._args = (options.args) ? options.args : [ "-n", "-w", "2", "-c", "1", host ];
this._regmatch = /=([0-9.]+?) ms/; // need to verify this
const defaultArgs = [ "-n", "-w", "2", "-c", "1", host ];
if (net.isIPv6(host)) {
defaultArgs.unshift("-6");
}
this._args = (options.args) ? options.args : defaultArgs;
this._regmatch = /=([0-9.]+?) ms/;
} else if (MAC) {
this._bin = "/sbin/ping";
this._args = (options.args) ? options.args : [ "-n", "-t", "2", "-c", "1", host ];
this._regmatch = /=([0-9.]+?) ms/;
} else {
throw new Error("Could not detect your ping binary.");
}