Closed mondwan closed 4 years ago
Yet another issued related #87
error in encoding during output { host: '����⠬�', alive: true, output: '\r\n' + '����� ����⠬� � yahoo.com [98.137.246.7] � 32 ���⠬� ������:\r\n' + '�⢥� �� 98.137.246.7: � ����=32 �६�=236�� TTL=46\r\n' + '\r\n' + '����⨪� Ping ��� 98.137.246.7:\r\n' + ' ����⮢: ��ࠢ���� = 1, ����祭� = 1, ����ﭮ = 0\r\n' + ' (0% �����)\r\n' + '�ਡ����⥫쭮� �६� �ਥ��-��।�� � ��:\r\n' + ' �������쭮� = 236�ᥪ, ���ᨬ��쭮� = 236 �ᥪ, �।��� = 236 �ᥪ\r\n', time: null, min: 'unknown', max: 'unknown', avg: 'unknown', stddev: 'NaN', numeric_host: '' }
as a result of which an error node_modules\ping\lib\parser\win.js:56 this._times.push(parseFloat(match[1], 10)); ^ TypeError: Cannot read property '1' of null
The parser is not tested on Korean?language.
Maybe, you can configure your nodejs such that Korean characters can be encoded in something bytecode or 0xaa.
The parser may work under this scenario
在 2019年11月23日週六 19:33,aarhipkaa notifications@github.com 寫道:
error in encoding during output { host: '����⠬�', alive: true, output: '\r\n' + '����� ����⠬� � yahoo.com [98.137.246.7] � 32 ���⠬� ������:\r\n' + '�⢥� �� 98.137.246.7: � ����=32 �६�=236�� TTL=46\r\n' + '\r\n' + '����⨪� Ping ��� 98.137.246.7:\r\n' + ' ����⮢: ��ࠢ���� = 1, ����祭� = 1, ����ﭮ = 0\r\n' + ' (0% �����)\r\n' + '�ਡ����⥫쭮� �६� �ਥ��-��।�� � ��:\r\n' + ' �������쭮� = 236�ᥪ, ���ᨬ��쭮� = 236 �ᥪ, �।��� = 236 �ᥪ\r\n', time: null, min: 'unknown', max: 'unknown', avg: 'unknown', stddev: 'NaN', numeric_host: '' }
as a result of which an error node_modules\ping\lib\parser\win.js:56 this._times.push(parseFloat(match[1], 10)); ^ TypeError: Cannot read property '1' of null
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/danielzzz/node-ping/issues/80?email_source=notifications&email_token=AA5YBI3QKDQSVSTK2X44JZLQVEIJZA5CNFSM4EQFNRUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEE7TIXA#issuecomment-557790300, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5YBI7W4D45RBEBTCMUC4DQVEIJZANCNFSM4EQFNRUA .
I have a Russian locale
here is the output from the standard cmd
C:>ping yahoo.com
Обмен пакетами с yahoo.com [98.137.246.7] с 32 байтами данных: Ответ от 98.137.246.7: число байт=32 время=218мс TTL=51 Ответ от 98.137.246.7: число байт=32 время=219мс TTL=51 Ответ от 98.137.246.7: число байт=32 время=217мс TTL=51 Ответ от 98.137.246.7: число байт=32 время=217мс TTL=51
Статистика Ping для 98.137.246.7: Пакетов: отправлено = 4, получено = 4, потеряно = 0 (0% потерь) Приблизительное время приема-передачи в мс: Минимальное = 217мсек, Максимальное = 219 мсек, Среднее = 217 мсек
This language is not yet support.
It will be great if you can send us a MR for patching this.
在 2019年11月23日週六 20:55,aarhipkaa notifications@github.com 寫道:
here is the output from the standard cmd
C:>ping yahoo.com
Обмен пакетами с yahoo.com [98.137.246.7] с 32 байтами данных: Ответ от 98.137.246.7: число байт=32 время=218мс TTL=51 Ответ от 98.137.246.7: число байт=32 время=219мс TTL=51 Ответ от 98.137.246.7: число байт=32 время=217мс TTL=51 Ответ от 98.137.246.7: число байт=32 время=217мс TTL=51
Статистика Ping для 98.137.246.7: Пакетов: отправлено = 4, получено = 4, потеряно = 0 (0% потерь) Приблизительное время приема-передачи в мс: Минимальное = 217мсек, Максимальное = 219 мсек, Среднее = 217 мсек
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/danielzzz/node-ping/issues/80?email_source=notifications&email_token=AA5YBI35QZKAZAGPQERGO7TQVER5BA5CNFSM4EQFNRUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEE7US4Y#issuecomment-557795699, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5YBI6EWWUPUTCGI67G2XDQVER5BANCNFSM4EQFNRUA .
this seems to be an embedded terminal issue. in the wsl terminal windows 10 is working fine
host: 'yahoo.com', alive: true, output: 'PING yahoo.com (98.137.246.8) 56(84) bytes of data.\n64 bytes from 98.137.246.8: icmp_seq=1 ttl=51 time=217 ms\n\n--- yahoo.com ping statistics ---\n1 packets transmitted, 1 received, 0% packet loss, time 0ms\nrtt min/avg/max/mdev = 217.117/217.117/217.117/0.000 ms\n', time: 217, min: '217.117', max: '217.117', avg: '217.117', stddev: '0.000', numeric_host: '98.137.246.8'
Ummm, as long as you are feeding the parser with supported language, it should be fined.
在 2019年11月23日週六 21:30,aarhipkaa notifications@github.com 寫道:
this seems to be an embedded terminal issue. in the wsl terminal windows 10 is working fine
host: 'yahoo.com', alive: true, output: 'PING yahoo.com (98.137.246.8) 56(84) bytes of data.\n64 bytes from 98.137.246.8: icmp_seq=1 ttl=51 time=217 ms\n\n--- yahoo.com ping statistics ---\n1 packets transmitted, 1 received, 0% packet loss, time 0ms\nrtt min/avg/max/mdev = 217.117/217.117/217.117/0.000 ms\n', time: 217, min: '217.117', max: '217.117', avg: '217.117', stddev: '0.000', numeric_host: '98.137.246.8'
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/danielzzz/node-ping/issues/80?email_source=notifications&email_token=AA5YBIYB4QN56HC6U3B63LDQVEV5ZA5CNFSM4EQFNRUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEE7VF5Y#issuecomment-557798135, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5YBI57Y3S5MRV6PTHIAPLQVEV5ZANCNFSM4EQFNRUA .
I did it!!! { host: '72.30.35.10', alive: true, output: '\r\n' + 'Обмен пакетами с 72.30.35.10 по с 32 байтами данных:\r\n' + 'Ответ от 72.30.35.10: число байт=32 время=164мс TTL=45\r\n' + 'Ответ от 72.30.35.10: число байт=32 время=162мс TTL=45\r\n' + 'Ответ от 72.30.35.10: число байт=32 время=163мс TTL=45\r\n' + 'Ответ от 72.30.35.10: число байт=32 время=162мс TTL=45\r\n' + 'Ответ от 72.30.35.10: число байт=32 время=162мс TTL=45\r\n' + 'Ответ от 72.30.35.10: число байт=32 время=162мс TTL=45\r\n' + 'Ответ от 72.30.35.10: число байт=32 время=162мс TTL=45\r\n' + 'Ответ от 72.30.35.10: число байт=32 время=162мс TTL=45\r\n' + 'Ответ от 72.30.35.10: число байт=32 время=162мс TTL=45\r\n' + 'Ответ от 72.30.35.10: число байт=32 время=162мс TTL=45\r\n' + '\r\n' + 'Статистика Ping для 72.30.35.10:\r\n' + ' Пакетов: отправлено = 10, получено = 10, потеряно = 0\r\n' + ' (0% потерь)\r\n' + 'Приблизительное время приема-передачи в мс:\r\n' + ' Минимальное = 162мсек, Максимальное = 164 мсек, Среднее = 162 мсек\r\n', time: '164', min: '162.000', max: '164.000', avg: '162.000', stddev: '2.000', numeric_host: '72.30.35.10' }
ping-promise.js var iconv = require('iconv-lite'); ... // Cache all lines from the system ping var outstring = []; ping.stdout.on('data', function (data) { if (platform === "win32") { // decoding from Buffer outstring.push(iconv.decode(data, "cp866").toString()); console.log(outstring); } else { outstring.push(String(data)); } });
win.js
'use strict';
var util = require('util'); var __ = require('underscore');
var base = require('./base');
/**
util.inherits(WinParser, base);
/**
@param {string} line - A line from system ping */ WinParser.prototype._processHeader = function (line) { let i = (line.indexOf("[") - 2); if (i > 0) { this._response.host = line.substring(line.lastIndexOf(" ", i) + 1, i + 1); this._response.numeric_host = (line.match(this._ipv4Regex))[0]; } else { this._response.numeric_host = this._response.host = (line.match(this._ipv4Regex))[0]; } this._changeState(this.STATES.BODY);
// Get host and numeric_host // var tokens = line.split(' ');
// this._response.host = tokens[1]; // if (this._ipv4Regex.test(this._response.host)) { // this._response.numeric_host = tokens[1]; // } else { // this._response.numeric_host = tokens[2].slice(1, -1); // }
// this._changeState(this.STATES.BODY); };
/**
@param {string} line - A line from system ping */ WinParser.prototype._processBody = function (line) {
let i = line.indexOf(this.localTime[0]) let substring = line.substring(line.lastIndexOf(" ", i), i) this._times.push((substring.match(this._timeRegex))[0]) this._changeState(this.STATES.FOOTER);
// var tokens = line.split(' '); // var kvps = __.filter(tokens, function (token) { // // Sometime it shows <1ms // return token.indexOf('=') >= 0 || token.indexOf('<') >= 0; // });
// // kvps.length >= 3 means target is pingable // if (kvps.length >= 3) { // // XXX: Assume time will alaways get keyword ms for all language // var timeKVP = __.find(kvps, function (kvp) { // return kvp.indexOf('мс') >= 0; // }); // var regExp = /([0-9.]+)/; // var match = regExp.exec(timeKVP);
// this._times.push(parseFloat(match[1], 10)); // }
// // Change state if it see a ':' at the end // if (line.slice(-1) === ':') { // this._changeState(this.STATES.FOOTER); // } };
/**
@param {string} line - A line from system ping */ WinParser.prototype._processFooter = function (line) { // XXX: Assume there is a keyword ms if (line.indexOf(this.localTime[1]) >= 0) { // XXX: Assume the ordering is Min Max Avg var regExp = /([0-9.]+)/g; var m1 = regExp.exec(line); var m2 = regExp.exec(line); var m3 = regExp.exec(line);
if (__.all([m1, m2, m3])) {
this._response.min = parseFloat(m1[1], 10);
this._response.max = parseFloat(m2[1], 10);
this._response.avg = parseFloat(m3[1], 10);
this._changeState(this.STATES.END);
}
} };
module.exports = WinParser;
for because of the locale "es", "line.indexOf(this.localTime[0])" should be replaced by "line.lastIndexOf(this.localTime[0])"
Thanks for your work.
Would you mind to send us a MR so that we can review, and try to patch this library in order to support Russian locale.
在 2019年11月27日週三 12:48,aarhipkaa notifications@github.com 寫道:
for because of the locale "es", "line.indexOf(this.localTime[0])" should be replaced by let i = line.lastIndexOf(this.localTime[0])
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/danielzzz/node-ping/issues/80?email_source=notifications&email_token=AA5YBI2BGRNH4JCX3V4N2LLQVX33LA5CNFSM4EQFNRUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFIIYWY#issuecomment-558926939, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5YBI4TILPZCYOHKX5RZQ3QVX33LANCNFSM4EQFNRUA .
Sorry, I don’t know what MR is. I recently started to study programming, and I have never written to Github before. Sorry for my English.
Welcome to the programming world.
MR stands for Merge request. Basically, it is nearly equivalent to asking for sending a diff file so that we can review, and apply your codes into our library. This is a common way for contribute opening source project in github (or other git repository)
You can take a look of the tutorial from github about how to work with MR
We are looking forward to see your patch regarding to your Russian locale patch :)
在 2019年11月27日週三 18:56,aarhipkaa notifications@github.com 寫道:
Sorry, I don’t know what MR is. I recently started to study programming, and I have never written to Github before. Sorry for my English.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/danielzzz/node-ping/issues/80?email_source=notifications&email_token=AA5YBI5XIV7DNEHPEUXZPATQVZG4TA5CNFSM4EQFNRUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFJD25Y#issuecomment-559037815, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5YBI4HGAS3W466TWZHBXLQVZG4TANCNFSM4EQFNRUA .
Hello. Last version(0.2.3) is not work on Windows 10 and Russian UTF8 locale.
Here is my fast fix:
--- ./win.js.orig 2020-03-26 08:47:17.000000000 +0200
+++ ./win.js 2020-03-26 10:41:46.495708439 +0200
@@ -11,6 +11,8 @@
*/
function WinParser(config) {
base.call(this, config);
+ var locale = Intl.DateTimeFormat().resolvedOptions().locale;
+ this.is_rus = /^ru/.test(locale);
this._ipv4Regex = /^([0-9]{1,3}\.){3}[0-9]{1,3}$/;
}
@@ -60,6 +62,10 @@
* @param {string} line - A line from system ping
*/
WinParser.prototype._processBody = function (line) {
+ if(this.is_rus){
+ //console.log("!", line.split('').map(c => c.charCodeAt(0)));
+ line = line.replace(/(=\d+)\ufffd\ufffd(\s+)/, '$1ms$2');
+ }
var tokens = line.split(' ');
var kvps = __.filter(tokens, function (token) {
// Sometime it shows <1ms
The problem is caused by the fact that the ping result string is not in utf8 encoding:
[
65533, 10405, 65533, 32, 65533, 65533,
32, 56, 46, 56, 46, 56,
46, 56, 58, 32, 65533, 6894,
32, 65533, 65533, 65533, 65533, 61,
51, 50, 32, 65533, 2412, 65533,
61, 49, 65533, 65533, 32, 84,
84, 76, 61, 53, 56
].map(c => String.fromCharCode(c));
So using "мс|мсек" search is not suitable!
Hi, there is a patch on #110 which try to fix this error. Please check this out on master branch. Thanks
Reopen if there are any issues
Same problem!
Windows11
Hi, as the original thread, there are no MRs, and there are no fixtures supplied. So, there are no fixes yet.
Please include the corresponding fixtures as examples so that some1 can implement them
On Tue, 19 Jul 2022, 19:13 Bauyrzhan Yessetov, @.***> wrote:
Same problem!
Windows11
[image: image] https://user-images.githubusercontent.com/2898361/179819927-c9051e94-594c-4565-bc24-a332a69c6100.png
— Reply to this email directly, view it on GitHub https://github.com/danielzzz/node-ping/issues/80#issuecomment-1189403251, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5YBI3KR5V5EM7G76CY7JDVU3V23ANCNFSM4EQFNRUA . You are receiving this because you modified the open/close state.Message ID: @.***>
Please include the corresponding fixtures as examples so that some1 can implement them
Hi, thank you for your reply, I'm expected the next result:
C:\Users\admin>ping 127.0.0.01
Обмен пакетами с 127.0.0.1 по с 32 байтами данных:
Ответ от 127.0.0.1: число байт=32 время<1мс TTL=128
Ответ от 127.0.0.1: число байт=32 время<1мс TTL=128
Ответ от 127.0.0.1: число байт=32 время<1мс TTL=128
Ответ от 127.0.0.1: число байт=32 время<1мс TTL=128
Статистика Ping для 127.0.0.1:
Пакетов: отправлено = 4, получено = 4, потеряно = 0
(0% потерь)
Приблизительное время приема-передачи в мс:
Минимальное = 0мсек, Максимальное = 0 мсек, Среднее = 0 мсек
Thanks for the samples. But, we need more for supporting a new language.
Please take a look the contributing guideline. Since not every developers can read the new language, we need the requester to provide sufficient information for us to work.
https://github.com/danielzzz/node-ping/blob/master/CONTRIBUTING.md
Let me know if you have any questions
On Wed, 20 Jul 2022, 03:12 Bauyrzhan Yessetov, @.***> wrote:
Please include the corresponding fixtures as examples so that some1 can implement them
Hi, thank you for your reply, I'm expected the next result:
C:\Users\admin>ping 127.0.0.01
Обмен пакетами с 127.0.0.1 по с 32 байтами данных: Ответ от 127.0.0.1: число байт=32 время<1мс TTL=128 Ответ от 127.0.0.1: число байт=32 время<1мс TTL=128 Ответ от 127.0.0.1: число байт=32 время<1мс TTL=128 Ответ от 127.0.0.1: число байт=32 время<1мс TTL=128
Статистика Ping для 127.0.0.1: Пакетов: отправлено = 4, получено = 4, потеряно = 0 (0% потерь) Приблизительное время приема-передачи в мс: Минимальное = 0мсек, Максимальное = 0 мсек, Среднее = 0 мсек
— Reply to this email directly, view it on GitHub https://github.com/danielzzz/node-ping/issues/80#issuecomment-1189728854, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5YBI4BNNRSL6TI6XX4AJ3VU5OB7ANCNFSM4EQFNRUA . You are receiving this because you modified the open/close state.Message ID: @.***>
Ah, cool. I will take a look, and see what I can do later on
As #72 illustrate, there are different locale setting on units
ms
Window setting. We need to refactor the Window's parser to better support the locale variation. Maybe scanning with a list of possible units?