add -6 to ping cmd if ipv6 address
This commit is contained in:
parent
f089bf73c3
commit
2a4695a774
|
@ -1,7 +1,7 @@
|
||||||
// https://github.com/ben-bradley/ping-lite/blob/master/ping-lite.js
|
// https://github.com/ben-bradley/ping-lite/blob/master/ping-lite.js
|
||||||
// Fixed on Windows
|
// Fixed on Windows
|
||||||
|
const net = require("net");
|
||||||
let spawn = require("child_process").spawn,
|
const spawn = require("child_process").spawn,
|
||||||
events = require("events"),
|
events = require("events"),
|
||||||
fs = require("fs"),
|
fs = require("fs"),
|
||||||
WIN = /^win/.test(process.platform),
|
WIN = /^win/.test(process.platform),
|
||||||
|
@ -24,14 +24,24 @@ function Ping(host, options) {
|
||||||
this._bin = "c:/windows/system32/ping.exe";
|
this._bin = "c:/windows/system32/ping.exe";
|
||||||
this._args = (options.args) ? options.args : [ "-n", "1", "-w", "5000", host ];
|
this._args = (options.args) ? options.args : [ "-n", "1", "-w", "5000", host ];
|
||||||
this._regmatch = /[><=]([0-9.]+?)ms/;
|
this._regmatch = /[><=]([0-9.]+?)ms/;
|
||||||
|
|
||||||
} else if (LIN) {
|
} else if (LIN) {
|
||||||
this._bin = "/bin/ping";
|
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) {
|
} else if (MAC) {
|
||||||
this._bin = "/sbin/ping";
|
this._bin = "/sbin/ping";
|
||||||
this._args = (options.args) ? options.args : [ "-n", "-t", "2", "-c", "1", host ];
|
this._args = (options.args) ? options.args : [ "-n", "-t", "2", "-c", "1", host ];
|
||||||
this._regmatch = /=([0-9.]+?) ms/;
|
this._regmatch = /=([0-9.]+?) ms/;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Could not detect your ping binary.");
|
throw new Error("Could not detect your ping binary.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue