ping-lite
Version:
A very simple ping wrapper
42 lines (34 loc) • 1.09 kB
JavaScript
;
const { spawn } = require('child_process');
const EventEmitter = require('events');
const fs = require('fs');
const WIN = /^win/.test(process.platform);
const LIN = /^linux/.test(process.platform);
const MAC = /^darwin/.test(process.platform);
class Ping extends EventEmitter {
constructor(host, options) {
this.host = host;
this.options = options;
if (WIN) {
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
}
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.');
}
this.i = 0;
}
send(cb) {
}
}