mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 16:54:04 +00:00
add -6 to ping cmd if ipv6 address
This commit is contained in:
parent
f089bf73c3
commit
2a4695a774
1 changed files with 14 additions and 4 deletions
|
@ -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.");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue