pingman 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
- import { extendedPingOptions, pingResponse } from "../types";
2
- import parser from "./parser.interface";
3
- declare class mac implements parser {
4
- config: extendedPingOptions | undefined;
5
- response: pingResponse;
6
- constructor(response: pingResponse, options?: extendedPingOptions);
7
- processHeader(line: string): void;
8
- processBody(line: string): void;
9
- processFooter(line: string): pingResponse;
10
- }
11
- export default mac;
1
+ import { extendedPingOptions, pingResponse } from "../types";
2
+ import parser from "./parser.interface";
3
+ declare class mac implements parser {
4
+ config: extendedPingOptions | undefined;
5
+ response: pingResponse;
6
+ constructor(response: pingResponse, options?: extendedPingOptions);
7
+ processHeader(line: string): void;
8
+ processBody(line: string): void;
9
+ processFooter(line: string): pingResponse;
10
+ }
11
+ export default mac;
@@ -1,46 +1,46 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class mac {
4
- constructor(response, options) {
5
- this.config = options;
6
- this.response = response;
7
- this.response.times = [];
8
- }
9
- processHeader(line) {
10
- // Get host and numeric_host
11
- let tokens = line.split(' ');
12
- this.response.host = tokens[1];
13
- this.response.numericHost = tokens[2].slice(1, -2);
14
- }
15
- processBody(line) {
16
- // XXX: Assume there is at least 3 '=' can be found
17
- let count = (line.match(/=/g) || []).length;
18
- if (count >= 3) {
19
- let regExp = /([0-9.]+)[ ]*ms/;
20
- let match = regExp.exec(line);
21
- match ? this.response.times.push(parseFloat(match[1])) : null;
22
- }
23
- }
24
- processFooter(line) {
25
- let packetLoss = line.match(/ ([\d.]+)%/);
26
- if (packetLoss) {
27
- this.response.packetLoss = packetLoss[1];
28
- }
29
- // XXX: Assume number of keywords '/' more than 3
30
- const count = (line.match(/[/]/g) || []).length;
31
- if (count >= 3) {
32
- const regExp = /([0-9.]+)/g;
33
- // XXX: Assume min avg max stddev
34
- let m1 = regExp.exec(line);
35
- let m2 = regExp.exec(line);
36
- let m3 = regExp.exec(line);
37
- let m4 = regExp.exec(line);
38
- m1 ? this.response.min = parseFloat(m1[1]) : null;
39
- m2 ? this.response.avg = parseFloat(m2[1]) : null;
40
- m3 ? this.response.max = parseFloat(m3[1]) : null;
41
- m4 ? this.response.stddev = parseFloat(m4[1]) : null;
42
- }
43
- return this.response;
44
- }
45
- }
46
- exports.default = mac;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class mac {
4
+ constructor(response, options) {
5
+ this.config = options;
6
+ this.response = response;
7
+ this.response.times = [];
8
+ }
9
+ processHeader(line) {
10
+ // Get host and numeric_host
11
+ let tokens = line.split(' ');
12
+ this.response.host = tokens[1];
13
+ this.response.numericHost = tokens[2].slice(1, -2);
14
+ }
15
+ processBody(line) {
16
+ // XXX: Assume there is at least 3 '=' can be found
17
+ let count = (line.match(/=/g) || []).length;
18
+ if (count >= 3) {
19
+ let regExp = /([0-9.]+)[ ]*ms/;
20
+ let match = regExp.exec(line);
21
+ match ? this.response.times.push(parseFloat(match[1])) : null;
22
+ }
23
+ }
24
+ processFooter(line) {
25
+ let packetLoss = line.match(/ ([\d.]+)%/);
26
+ if (packetLoss) {
27
+ this.response.packetLoss = packetLoss[1];
28
+ }
29
+ // XXX: Assume number of keywords '/' more than 3
30
+ const count = (line.match(/[/]/g) || []).length;
31
+ if (count >= 3) {
32
+ const regExp = /([0-9.]+)/g;
33
+ // XXX: Assume min avg max stddev
34
+ let m1 = regExp.exec(line);
35
+ let m2 = regExp.exec(line);
36
+ let m3 = regExp.exec(line);
37
+ let m4 = regExp.exec(line);
38
+ m1 ? this.response.min = parseFloat(m1[1]) : null;
39
+ m2 ? this.response.avg = parseFloat(m2[1]) : null;
40
+ m3 ? this.response.max = parseFloat(m3[1]) : null;
41
+ m4 ? this.response.stddev = parseFloat(m4[1]) : null;
42
+ }
43
+ return this.response;
44
+ }
45
+ }
46
+ exports.default = mac;
@@ -1,8 +1,8 @@
1
- import { extendedPingOptions, pingResponse } from "../types";
2
- interface parser {
3
- config?: extendedPingOptions;
4
- processHeader(line: string): void;
5
- processBody(line: string): void;
6
- processFooter(line: string): pingResponse;
7
- }
8
- export default parser;
1
+ import { extendedPingOptions, pingResponse } from "../types";
2
+ interface parser {
3
+ config?: extendedPingOptions;
4
+ processHeader(line: string): void;
5
+ processBody(line: string): void;
6
+ processFooter(line: string): pingResponse;
7
+ }
8
+ export default parser;
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,3 @@
1
- import { extendedPingOptions, pingResponse } from '../types';
2
- declare function parserFactory(platform: string, output?: string[], options?: extendedPingOptions): pingResponse;
3
- export default parserFactory;
1
+ import { extendedPingOptions, pingResponse } from '../types';
2
+ declare function parserFactory(platform: string, output?: string[], options?: extendedPingOptions): pingResponse;
3
+ export default parserFactory;
@@ -1,122 +1,122 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const helper_1 = require("../helper");
7
- const errors_1 = require("../errors");
8
- const windows_1 = __importDefault(require("./windows"));
9
- const mac_1 = __importDefault(require("./mac"));
10
- const linux_1 = __importDefault(require("./linux"));
11
- const messages_1 = require("../messages");
12
- //create instance of parser based on operating system
13
- function parserFactory(platform, output, options) {
14
- let parser;
15
- let isWindows = false;
16
- if (!(0, helper_1.isPlatformSupported)(platform)) {
17
- throw new errors_1.supportedError(messages_1.ERROR_MESSAGES.PLATFORM_NOT_SUPPORTED.replace('platform', platform));
18
- }
19
- if (platform === 'win32') {
20
- parser = new windows_1.default(defaultResponse, options);
21
- isWindows = true;
22
- }
23
- else if (platform === 'darwin') {
24
- parser = new mac_1.default(defaultResponse, options);
25
- }
26
- else {
27
- parser = new linux_1.default(defaultResponse, options);
28
- }
29
- let result = parseOutput(parser, isWindows, output);
30
- return result;
31
- }
32
- //parsing output line by line
33
- function parseOutput(parser, isWindows, output) {
34
- let lines = output === null || output === void 0 ? void 0 : output.join('').split('\n');
35
- let state = 0;
36
- let parsedOutput = defaultResponse;
37
- lines === null || lines === void 0 ? void 0 : lines.forEach((line) => {
38
- line = line.replace(stripRegex, '');
39
- if (line.length === 0) {
40
- // Do nothing if this is an empty line
41
- }
42
- else if (state === states.HEADER) {
43
- parser.processHeader(line);
44
- state = states.BODY;
45
- }
46
- else if (state === states.BODY) {
47
- (!checkIfBodyEnded(line, isWindows)) ? parser.processBody(line) : state = states.FOOTER;
48
- }
49
- else if (state === states.FOOTER) {
50
- parsedOutput = parser.processFooter(line);
51
- }
52
- });
53
- let result = createResult(parsedOutput, lines);
54
- return result;
55
- }
56
- //function to check if body ended and footer began
57
- function checkIfBodyEnded(line, windows) {
58
- if (windows) {
59
- let isPingSummaryLineShown = line.slice(-1) === ':';
60
- if (isPingSummaryLineShown) {
61
- return true;
62
- }
63
- }
64
- else {
65
- // Change state if it see a '---'
66
- if (line.indexOf('---') >= 0) {
67
- return true;
68
- }
69
- }
70
- return false;
71
- }
72
- //Function to calculate and create the result
73
- function createResult(result, lines) {
74
- var _a;
75
- // Concat output
76
- result.output = lines === null || lines === void 0 ? void 0 : lines.join('\n');
77
- // Determine alive
78
- result.alive = ((_a = result === null || result === void 0 ? void 0 : result.times) === null || _a === void 0 ? void 0 : _a.length) > 0;
79
- // Update time at first successful line
80
- if (result.alive) {
81
- result.time = result.times[0];
82
- }
83
- // Get stddev
84
- if (result.stddev === undefined && result.alive) {
85
- let N = result.times.length;
86
- const mean = result.times.reduce((a, b) => a + b) / N;
87
- const stddev = Math.sqrt(result.times.map(x => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / N);
88
- result.stddev = stddev;
89
- }
90
- // Fix min, avg, max, stddev up to 3 decimal points
91
- ['min', 'avg', 'max', 'stddev', 'packetLoss'].forEach((key) => {
92
- let v = result[key];
93
- if (typeof v === 'number') {
94
- result[key] = v.toFixed(3);
95
- }
96
- });
97
- return result;
98
- }
99
- //Default response object
100
- const defaultResponse = {
101
- host: undefined,
102
- numericHost: undefined,
103
- alive: false,
104
- output: undefined,
105
- time: undefined,
106
- times: [],
107
- min: undefined,
108
- max: undefined,
109
- avg: undefined,
110
- stddev: undefined,
111
- packetLoss: undefined,
112
- bufferSize: undefined
113
- };
114
- //to strip space present at end of string
115
- const stripRegex = /[ ]*\r?\n?$/g;
116
- //States of parsing - local use only
117
- const states = {
118
- HEADER: 0,
119
- BODY: 1,
120
- FOOTER: 2
121
- };
122
- exports.default = parserFactory;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const helper_1 = require("../helper");
7
+ const errors_1 = require("../errors");
8
+ const windows_1 = __importDefault(require("./windows"));
9
+ const mac_1 = __importDefault(require("./mac"));
10
+ const linux_1 = __importDefault(require("./linux"));
11
+ const messages_1 = require("../messages");
12
+ //create instance of parser based on operating system
13
+ function parserFactory(platform, output, options) {
14
+ let parser;
15
+ let isWindows = false;
16
+ if (!(0, helper_1.isPlatformSupported)(platform)) {
17
+ throw new errors_1.supportedError(messages_1.ERROR_MESSAGES.PLATFORM_NOT_SUPPORTED.replace('platform', platform));
18
+ }
19
+ if (platform === 'win32') {
20
+ parser = new windows_1.default(defaultResponse, options);
21
+ isWindows = true;
22
+ }
23
+ else if (platform === 'darwin') {
24
+ parser = new mac_1.default(defaultResponse, options);
25
+ }
26
+ else {
27
+ parser = new linux_1.default(defaultResponse, options);
28
+ }
29
+ let result = parseOutput(parser, isWindows, output);
30
+ return result;
31
+ }
32
+ //parsing output line by line
33
+ function parseOutput(parser, isWindows, output) {
34
+ let lines = output === null || output === void 0 ? void 0 : output.join('').split('\n');
35
+ let state = 0;
36
+ let parsedOutput = defaultResponse;
37
+ lines === null || lines === void 0 ? void 0 : lines.forEach((line) => {
38
+ line = line.replace(stripRegex, '');
39
+ if (line.length === 0) {
40
+ // Do nothing if this is an empty line
41
+ }
42
+ else if (state === states.HEADER) {
43
+ parser.processHeader(line);
44
+ state = states.BODY;
45
+ }
46
+ else if (state === states.BODY) {
47
+ (!checkIfBodyEnded(line, isWindows)) ? parser.processBody(line) : state = states.FOOTER;
48
+ }
49
+ else if (state === states.FOOTER) {
50
+ parsedOutput = parser.processFooter(line);
51
+ }
52
+ });
53
+ let result = createResult(parsedOutput, lines);
54
+ return result;
55
+ }
56
+ //function to check if body ended and footer began
57
+ function checkIfBodyEnded(line, windows) {
58
+ if (windows) {
59
+ let isPingSummaryLineShown = line.slice(-1) === ':';
60
+ if (isPingSummaryLineShown) {
61
+ return true;
62
+ }
63
+ }
64
+ else {
65
+ // Change state if it see a '---'
66
+ if (line.indexOf('---') >= 0) {
67
+ return true;
68
+ }
69
+ }
70
+ return false;
71
+ }
72
+ //Function to calculate and create the result
73
+ function createResult(result, lines) {
74
+ var _a;
75
+ // Concat output
76
+ result.output = lines === null || lines === void 0 ? void 0 : lines.join('\n');
77
+ // Determine alive
78
+ result.alive = ((_a = result === null || result === void 0 ? void 0 : result.times) === null || _a === void 0 ? void 0 : _a.length) > 0;
79
+ // Update time at first successful line
80
+ if (result.alive) {
81
+ result.time = result.times[0];
82
+ }
83
+ // Get stddev
84
+ if (result.stddev === undefined && result.alive) {
85
+ let N = result.times.length;
86
+ const mean = result.times.reduce((a, b) => a + b) / N;
87
+ const stddev = Math.sqrt(result.times.map(x => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / N);
88
+ result.stddev = stddev;
89
+ }
90
+ // Fix min, avg, max, stddev up to 3 decimal points
91
+ ['min', 'avg', 'max', 'stddev', 'packetLoss'].forEach((key) => {
92
+ let v = result[key];
93
+ if (typeof v === 'number') {
94
+ result[key] = v.toFixed(3);
95
+ }
96
+ });
97
+ return result;
98
+ }
99
+ //Default response object
100
+ const defaultResponse = {
101
+ host: undefined,
102
+ numericHost: undefined,
103
+ alive: false,
104
+ output: undefined,
105
+ time: undefined,
106
+ times: [],
107
+ min: undefined,
108
+ max: undefined,
109
+ avg: undefined,
110
+ stddev: undefined,
111
+ packetLoss: undefined,
112
+ bufferSize: undefined
113
+ };
114
+ //to strip space present at end of string
115
+ const stripRegex = /[ ]*\r?\n?$/g;
116
+ //States of parsing - local use only
117
+ const states = {
118
+ HEADER: 0,
119
+ BODY: 1,
120
+ FOOTER: 2
121
+ };
122
+ exports.default = parserFactory;
@@ -1,13 +1,13 @@
1
- import { extendedPingOptions, pingResponse } from "../types";
2
- import parser from "./parser.interface";
3
- declare class windows implements parser {
4
- config: extendedPingOptions | undefined;
5
- response: pingResponse;
6
- constructor(response: pingResponse, options?: extendedPingOptions);
7
- processHeader(line: string): void;
8
- processBody(line: string): void;
9
- processFooter(line: string): pingResponse;
10
- processIPV4Body(dataFields: string[]): void;
11
- processIPV6Body(dataFields: string[]): void;
12
- }
13
- export default windows;
1
+ import { extendedPingOptions, pingResponse } from "../types";
2
+ import parser from "./parser.interface";
3
+ declare class windows implements parser {
4
+ config: extendedPingOptions | undefined;
5
+ response: pingResponse;
6
+ constructor(response: pingResponse, options?: extendedPingOptions);
7
+ processHeader(line: string): void;
8
+ processBody(line: string): void;
9
+ processFooter(line: string): pingResponse;
10
+ processIPV4Body(dataFields: string[]): void;
11
+ processIPV6Body(dataFields: string[]): void;
12
+ }
13
+ export default windows;
@@ -1,110 +1,110 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class windows {
4
- constructor(response, options) {
5
- this.config = options;
6
- this.response = response;
7
- this.response.times = [];
8
- }
9
- processHeader(line) {
10
- let isPingNumeric = line.indexOf('[') === -1;
11
- const ipv4v6Regex = /((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))/;
12
- // Get host and numeric_host
13
- let words = line.split(' ');
14
- if (isPingNumeric) {
15
- // For those missing [***], get the first token which match IPV4 regex
16
- this.response.host = words.find((word) => {
17
- return ipv4v6Regex.test(word);
18
- });
19
- this.response.numericHost = this.response.host;
20
- }
21
- else {
22
- // For those has [***], anchor with such token
23
- let numericHost = words.find(function (word) {
24
- return word.indexOf('[') !== -1;
25
- });
26
- if (numericHost) {
27
- let numericHostIndex = words.indexOf(numericHost);
28
- let match = /\[(.*)\]/.exec(numericHost);
29
- if (match) {
30
- // Capture IP inside [] only. refs #71
31
- this.response.numericHost = match[1];
32
- }
33
- this.response.host = words[numericHostIndex - 1];
34
- }
35
- }
36
- }
37
- processBody(line) {
38
- var _a;
39
- let isIPV6 = (_a = this.config) === null || _a === void 0 ? void 0 : _a.IPV6;
40
- let words = line.split(' ');
41
- let dataFields = words.filter((word) => {
42
- let isDataField = word.indexOf('=') >= 0 || word.indexOf('<') >= 0;
43
- return isDataField;
44
- });
45
- //if IPV6, body does not have as many fields as IPV4 based on testing
46
- if (isIPV6) {
47
- this.processIPV6Body(dataFields);
48
- }
49
- else {
50
- this.processIPV4Body(dataFields);
51
- }
52
- }
53
- processFooter(line) {
54
- let packetLoss = line.match(/([\d.]+)%/);
55
- if (packetLoss) {
56
- this.response.packetLoss = packetLoss[1];
57
- }
58
- // XXX: Assume there is a keyword ms
59
- if (line.search(/(ms|мсек)/i) >= 0) {
60
- // XXX: Assume the ordering is Min Max Avg
61
- let regExp = /([0-9.]+)/g;
62
- let m1 = regExp.exec(line);
63
- let m2 = regExp.exec(line);
64
- let m3 = regExp.exec(line);
65
- m1 ? this.response.min = parseFloat(m1[1]) : null;
66
- m2 ? this.response.max = parseFloat(m2[1]) : null;
67
- m3 ? this.response.avg = parseFloat(m3[1]) : null;
68
- }
69
- return this.response;
70
- }
71
- //method to process IPV4 Specific Body
72
- processIPV4Body(dataFields) {
73
- var _a, _b;
74
- const expectDataFieldInReplyLine = 3;
75
- let isReplyLine = dataFields.length >= expectDataFieldInReplyLine;
76
- if (isReplyLine) {
77
- // XXX: Assume time will alaways get keyword ms for all language
78
- let timeField = dataFields.find((field) => {
79
- return field.search(/(ms|мс)/i) >= 0;
80
- });
81
- if (timeField) {
82
- let regExp = /([0-9.]+)/;
83
- let match = regExp.exec(timeField);
84
- let timeFieldIndex = dataFields.indexOf(timeField);
85
- match ? (_b = (_a = this.response) === null || _a === void 0 ? void 0 : _a.times) === null || _b === void 0 ? void 0 : _b.push(parseFloat(match[1])) : null;
86
- // XXX: Assume byte field will be just before the time field
87
- let bytesField = dataFields[timeFieldIndex - 1];
88
- match = regExp.exec(bytesField);
89
- match ? this.response.bufferSize = parseFloat(match[1]) : null;
90
- }
91
- }
92
- }
93
- //method to process IPV6 Specific Body
94
- processIPV6Body(dataFields) {
95
- var _a, _b;
96
- let expectDataFieldInReplyLine = 1;
97
- if (dataFields.length >= expectDataFieldInReplyLine) {
98
- // XXX: Assume time will alaways get keyword ms for all language
99
- let timeField = dataFields.find((dataField) => {
100
- return dataField.search(/(ms|мс)/i) >= 0;
101
- });
102
- const regExp = /([0-9.]+)/;
103
- if (timeField) {
104
- let match = regExp.exec(timeField);
105
- match ? (_b = (_a = this.response) === null || _a === void 0 ? void 0 : _a.times) === null || _b === void 0 ? void 0 : _b.push(parseFloat(match[1])) : null;
106
- }
107
- }
108
- }
109
- }
110
- exports.default = windows;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class windows {
4
+ constructor(response, options) {
5
+ this.config = options;
6
+ this.response = response;
7
+ this.response.times = [];
8
+ }
9
+ processHeader(line) {
10
+ let isPingNumeric = line.indexOf('[') === -1;
11
+ const ipv4v6Regex = /((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))/;
12
+ // Get host and numeric_host
13
+ let words = line.split(' ');
14
+ if (isPingNumeric) {
15
+ // For those missing [***], get the first token which match IPV4 regex
16
+ this.response.host = words.find((word) => {
17
+ return ipv4v6Regex.test(word);
18
+ });
19
+ this.response.numericHost = this.response.host;
20
+ }
21
+ else {
22
+ // For those has [***], anchor with such token
23
+ let numericHost = words.find(function (word) {
24
+ return word.indexOf('[') !== -1;
25
+ });
26
+ if (numericHost) {
27
+ let numericHostIndex = words.indexOf(numericHost);
28
+ let match = /\[(.*)\]/.exec(numericHost);
29
+ if (match) {
30
+ // Capture IP inside [] only. refs #71
31
+ this.response.numericHost = match[1];
32
+ }
33
+ this.response.host = words[numericHostIndex - 1];
34
+ }
35
+ }
36
+ }
37
+ processBody(line) {
38
+ var _a;
39
+ let isIPV6 = (_a = this.config) === null || _a === void 0 ? void 0 : _a.IPV6;
40
+ let words = line.split(' ');
41
+ let dataFields = words.filter((word) => {
42
+ let isDataField = word.indexOf('=') >= 0 || word.indexOf('<') >= 0;
43
+ return isDataField;
44
+ });
45
+ //if IPV6, body does not have as many fields as IPV4 based on testing
46
+ if (isIPV6) {
47
+ this.processIPV6Body(dataFields);
48
+ }
49
+ else {
50
+ this.processIPV4Body(dataFields);
51
+ }
52
+ }
53
+ processFooter(line) {
54
+ let packetLoss = line.match(/([\d.]+)%/);
55
+ if (packetLoss) {
56
+ this.response.packetLoss = packetLoss[1];
57
+ }
58
+ // XXX: Assume there is a keyword ms
59
+ if (line.search(/(ms|мсек)/i) >= 0) {
60
+ // XXX: Assume the ordering is Min Max Avg
61
+ let regExp = /([0-9.]+)/g;
62
+ let m1 = regExp.exec(line);
63
+ let m2 = regExp.exec(line);
64
+ let m3 = regExp.exec(line);
65
+ m1 ? this.response.min = parseFloat(m1[1]) : null;
66
+ m2 ? this.response.max = parseFloat(m2[1]) : null;
67
+ m3 ? this.response.avg = parseFloat(m3[1]) : null;
68
+ }
69
+ return this.response;
70
+ }
71
+ //method to process IPV4 Specific Body
72
+ processIPV4Body(dataFields) {
73
+ var _a, _b;
74
+ const expectDataFieldInReplyLine = 3;
75
+ let isReplyLine = dataFields.length >= expectDataFieldInReplyLine;
76
+ if (isReplyLine) {
77
+ // XXX: Assume time will alaways get keyword ms for all language
78
+ let timeField = dataFields.find((field) => {
79
+ return field.search(/(ms|мс)/i) >= 0;
80
+ });
81
+ if (timeField) {
82
+ let regExp = /([0-9.]+)/;
83
+ let match = regExp.exec(timeField);
84
+ let timeFieldIndex = dataFields.indexOf(timeField);
85
+ match ? (_b = (_a = this.response) === null || _a === void 0 ? void 0 : _a.times) === null || _b === void 0 ? void 0 : _b.push(parseFloat(match[1])) : null;
86
+ // XXX: Assume byte field will be just before the time field
87
+ let bytesField = dataFields[timeFieldIndex - 1];
88
+ match = regExp.exec(bytesField);
89
+ match ? this.response.bufferSize = parseFloat(match[1]) : null;
90
+ }
91
+ }
92
+ }
93
+ //method to process IPV6 Specific Body
94
+ processIPV6Body(dataFields) {
95
+ var _a, _b;
96
+ let expectDataFieldInReplyLine = 1;
97
+ if (dataFields.length >= expectDataFieldInReplyLine) {
98
+ // XXX: Assume time will alaways get keyword ms for all language
99
+ let timeField = dataFields.find((dataField) => {
100
+ return dataField.search(/(ms|мс)/i) >= 0;
101
+ });
102
+ const regExp = /([0-9.]+)/;
103
+ if (timeField) {
104
+ let match = regExp.exec(timeField);
105
+ match ? (_b = (_a = this.response) === null || _a === void 0 ? void 0 : _a.times) === null || _b === void 0 ? void 0 : _b.push(parseFloat(match[1])) : null;
106
+ }
107
+ }
108
+ }
109
+ }
110
+ exports.default = windows;
@@ -1,3 +1,3 @@
1
- import { commandBuilder } from "./types";
2
- declare const execute: (builtCommand: commandBuilder) => Promise<any>;
3
- export default execute;
1
+ import { commandBuilder } from "./types";
2
+ declare const execute: (builtCommand: commandBuilder) => Promise<any>;
3
+ export default execute;