diff --git a/io/ping/88-ping.js b/io/ping/88-ping.js index e178e3c8..c7496cf8 100644 --- a/io/ping/88-ping.js +++ b/io/ping/88-ping.js @@ -32,21 +32,21 @@ module.exports = function(RED) { else if (plat == "darwin") { ex = spawn('ping', ['-n', '-t', '5', '-c', '1', node.host]); } else { node.error("Sorry - your platform - "+plat+" - is not recognised."); } var res = false; + var line = ""; + //var regex = /from.*time.(.*)ms/; + var regex = /=.*[<|=]([0-9]*).*TTL|ttl..*=([0-9\.]*)/; ex.stdout.on('data', function (data) { - //console.log('[ping] stdout: ' + data.toString()); - var regex = /=.*[<|=]([0-9]*).*TTL|ttl..*=([0-9]*)/; - //var regex = /from.*time.(.*)ms/; - var m = regex.exec(data.toString())||""; - if (m !== '') { - if (m[1]) { res = Number(m[1]); } - if (m[2]) { res = Number(m[2]); } - } + line += data.toString(); }); ex.stderr.on('data', function (data) { //console.log('[ping] stderr: ' + data); }); ex.on('close', function (code) { - //console.log('[ping] result: ' + code); + var m = regex.exec(line)||""; + if (m !== '') { + if (m[1]) { res = Number(m[1]); } + if (m[2]) { res = Number(m[2]); } + } var msg = { payload:false, topic:node.host }; if (code === 0) { msg = { payload:res, topic:node.host }; } node.send(msg); diff --git a/io/ping/package.json b/io/ping/package.json index 67bb0884..ca5b23a0 100644 --- a/io/ping/package.json +++ b/io/ping/package.json @@ -1,6 +1,6 @@ { "name" : "node-red-node-ping", - "version" : "0.0.1", + "version" : "0.0.3", "description" : "A Node-RED node to ping a remote server, for use as a keep-alive check.", "dependencies" : { },