Comparing version 0.4.0 to 0.4.1
@@ -10,2 +10,3 @@ 'use strict'; | ||
* @typedef {object} PingResponse | ||
* @param {string} inputHost - The input IP address or HOST | ||
* @param {string} host - The input IP address or HOST | ||
@@ -26,5 +27,6 @@ * @param {string} numeric_host - Target IP address | ||
* | ||
* @param {string} addr - Hostname or ip addres | ||
* @param {PingConfig} config - Config object in probe() | ||
*/ | ||
function parser(config) { | ||
function parser(addr, config) { | ||
// Initial state is 0 | ||
@@ -35,2 +37,3 @@ this._state = 0; | ||
this._response = { | ||
inputHost: addr, | ||
host: 'unknown', | ||
@@ -37,0 +40,0 @@ alive: false, |
@@ -18,2 +18,3 @@ 'use strict'; | ||
* Create a parser for a given platform | ||
* @param {string} addr - Hostname or ip addres | ||
* @param {string} platform - Name of the platform | ||
@@ -24,3 +25,3 @@ * @param {PingConfig} [config] - Config object in probe() | ||
*/ | ||
factory.createParser = function (platform, config) { | ||
factory.createParser = function (addr, platform, config) { | ||
// Avoid function reassignment | ||
@@ -35,7 +36,7 @@ var _config = config || {}; | ||
if (builderFactory.isWindow(platform)) { | ||
ret = new WinParser(_config); | ||
ret = new WinParser(addr, _config); | ||
} else if (builderFactory.isMacOS(platform)) { | ||
ret = new MacParser(_config); | ||
ret = new MacParser(addr, _config); | ||
} else if (builderFactory.isLinux(platform)) { | ||
ret = new LinuxParser(_config); | ||
ret = new LinuxParser(addr, _config); | ||
} | ||
@@ -42,0 +43,0 @@ |
@@ -9,6 +9,8 @@ 'use strict'; | ||
* @constructor | ||
* | ||
* @param {string} addr - Hostname or ip addres | ||
* @param {PingConfig} config - Config object in probe() | ||
*/ | ||
function LinuxParser(config) { | ||
base.call(this, config); | ||
function LinuxParser(addr, config) { | ||
base.call(this, addr, config); | ||
} | ||
@@ -15,0 +17,0 @@ |
@@ -10,6 +10,8 @@ 'use strict'; | ||
* @constructor | ||
* | ||
* @param {string} addr - Hostname or ip addres | ||
* @param {PingConfig} config - Config object in probe() | ||
*/ | ||
function MacParser(config) { | ||
base.call(this, config); | ||
function MacParser(addr, config) { | ||
base.call(this, addr, config); | ||
} | ||
@@ -16,0 +18,0 @@ |
@@ -10,6 +10,8 @@ 'use strict'; | ||
* @constructor | ||
* | ||
* @param {string} addr - Hostname or ip addres | ||
* @param {PingConfig} config - Config object in probe() | ||
*/ | ||
function WinParser(config) { | ||
base.call(this, config); | ||
function WinParser(addr, config) { | ||
base.call(this, addr, config); | ||
this._ipv4Regex = /^([0-9]{1,3}\.){3}[0-9]{1,3}$/; | ||
@@ -16,0 +18,0 @@ } |
@@ -57,3 +57,3 @@ 'use strict'; | ||
// Initial parser | ||
var parser = parserFactory.createParser(platform, _config); | ||
var parser = parserFactory.createParser(addr, platform, _config); | ||
@@ -60,0 +60,0 @@ // Register events from system ping |
@@ -25,3 +25,3 @@ { | ||
"description": "a simple wrapper for ping", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"homepage": "http://github.com/danielzzz/node-ping", | ||
@@ -28,0 +28,0 @@ "license": "MIT", |
@@ -5,3 +5,3 @@ # NODE-PING [![Build Status](https://travis-ci.com/danielzzz/node-ping.svg?branch=master)](https://travis-ci.com/danielzzz/node-ping) | ||
@last-modified: 2020-12-19 | ||
@last-modified: 2020-12-26 | ||
@@ -45,3 +45,3 @@ # LICENSE MIT | ||
timeout: 10, | ||
// WARNING: -i 2 may not work in other platform like window | ||
// WARNING: -i 2 may not work in other platform like windows | ||
extra: ['-i', '2'], | ||
@@ -77,3 +77,3 @@ }; | ||
hosts.forEach(function (host) { | ||
// WARNING: -i 2 argument may not work in other platform like window | ||
// WARNING: -i 2 argument may not work in other platform like windows | ||
ping.promise.probe(host, { | ||
@@ -108,3 +108,3 @@ timeout: 10, | ||
for(let host of hosts){ | ||
// WARNING: -i 2 argument may not work in other platform like window | ||
// WARNING: -i 2 argument may not work in other platform like windows | ||
let res = await ping.promise.probe(host, { | ||
@@ -137,3 +137,3 @@ timeout: 10, | ||
* @property {number} packetSize - Specifies the number of data bytes to be sent | ||
Default: Linux / MAC: 56 Bytes, Window: 32 Bytes | ||
Default: Linux / MAC: 56 Bytes, Windows: 32 Bytes | ||
* @property {string[]} extra - Optional options does not provided | ||
@@ -162,3 +162,4 @@ */ | ||
* @typedef {object} PingResponse | ||
* @param {string} host - The input IP address or HOST | ||
* @param {string} inputHost - The input IP address or HOST | ||
* @param {string} host - Parsed host from system command's output | ||
* @param {string} numeric_host - Target IP address | ||
@@ -198,2 +199,5 @@ * @param {boolean} alive - True for existed host | ||
* For questions regarding to the defintions of `host`, `inputHost`, and `numeric_host`, please checkout | ||
discussions in [#133](https://github.com/danielzzz/node-ping/issues/133) | ||
# Contributing | ||
@@ -200,0 +204,0 @@ |
{ | ||
"macos_en_sample1": { | ||
"inputHost": "whatever", | ||
"host": "google.com", | ||
@@ -21,2 +22,3 @@ "numeric_host": "172.217.24.46", | ||
"linux_en_sample1": { | ||
"inputHost": "whatever", | ||
"host": "localhost", | ||
@@ -40,2 +42,3 @@ "numeric_host": "127.0.0.1", | ||
"linux_en_sample2": { | ||
"inputHost": "whatever", | ||
"host": "10.48.249.8", | ||
@@ -66,2 +69,3 @@ "numeric_host": "10.48.249.8", | ||
"linux_en_sample3": { | ||
"inputHost": "whatever", | ||
"host": "10.48.249.150", | ||
@@ -80,2 +84,3 @@ "numeric_host": "10.48.249.150", | ||
"linux_en_v6_sample1": { | ||
"inputHost": "whatever", | ||
"host": "2606:4700:4700::1111", | ||
@@ -97,2 +102,3 @@ "numeric_host": "2606:4700:4700::1111", | ||
"linux_en_v6_sample2": { | ||
"inputHost": "whatever", | ||
"host": "one.one.one.one", | ||
@@ -114,2 +120,3 @@ "numeric_host": "2606:4700:4700::1111", | ||
"window_en_sample1": { | ||
"inputHost": "whatever", | ||
"host": "www.some-domain.com", | ||
@@ -134,2 +141,3 @@ "numeric_host": "127.0.0.1", | ||
"window_fr_sample1": { | ||
"inputHost": "whatever", | ||
"host": "127.0.0.1", | ||
@@ -153,2 +161,3 @@ "numeric_host": "127.0.0.1", | ||
"window_fr_sample2": { | ||
"inputHost": "whatever", | ||
"host": "8.8.8.8", | ||
@@ -172,2 +181,3 @@ "numeric_host": "8.8.8.8", | ||
"window_ja_sample1": { | ||
"inputHost": "whatever", | ||
"host": "google.com", | ||
@@ -191,2 +201,3 @@ "numeric_host": "216.58.197.142", | ||
"window_ja_sample2": { | ||
"inputHost": "whatever", | ||
"host": "8.8.8.8", | ||
@@ -210,2 +221,3 @@ "numeric_host": "8.8.8.8", | ||
"window_zh_sample1": { | ||
"inputHost": "whatever", | ||
"host": "google.com", | ||
@@ -229,2 +241,3 @@ "numeric_host": "216.58.203.14", | ||
"window_zh_sample2": { | ||
"inputHost": "whatever", | ||
"host": "google.com", | ||
@@ -248,2 +261,3 @@ "numeric_host": "216.58.203.14", | ||
"window_zh_sample3": { | ||
"inputHost": "whatever", | ||
"host": "127.0.0.1", | ||
@@ -267,2 +281,3 @@ "numeric_host": "127.0.0.1", | ||
"window_ru_sample1": { | ||
"inputHost": "whatever", | ||
"host": "8.8.8.8", | ||
@@ -285,3 +300,5 @@ "numeric_host": "8.8.8.8", | ||
}, | ||
"window_de_v6_sample": { "host": "google.de", | ||
"window_de_v6_sample": { | ||
"inputHost": "whatever", | ||
"host": "google.de", | ||
"alive": true, | ||
@@ -288,0 +305,0 @@ "output": "Ping wird ausgeführt für google.de [2a00:1450:4001:810::2003] von 3001:4cb0:0:f282:ddf1:bec9:1e0:bfa9 mit 32 Bytes Daten:\nAntwort von 2a00:1450:4001:810::2003: Zeit=11ms\nAntwort von 2a00:1450:4001:810::2003: Zeit=11ms\nAntwort von 2a00:1450:4001:810::2003: Zeit=18ms\nAntwort von 2a00:1450:4001:810::2003: Zeit=11ms\n\nPing-Statistik für 2a00:1450:4001:810::2003:\n Pakete: Gesendet = 4, Empfangen = 4, Verloren = 0\n (0% Verlust),\nCa. Zeitangaben in Millisek.:\n Minimum = 11ms, Maximum = 18ms, Mittelwert = 12ms\n", |
108562
2949
202