pingman 1.1.4 → 1.2.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.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 Govind S
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Govind S
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,3 +1,3 @@
1
- import { commandBuilder, extendedPingOptions } from '../types';
2
- declare function builderFactory(ip: string, platform: string, options?: extendedPingOptions): commandBuilder;
3
- export default builderFactory;
1
+ import { commandBuilder, extendedPingOptions } from '../types';
2
+ declare function builderFactory(ip: string, platform: string, options?: extendedPingOptions): commandBuilder;
3
+ export default builderFactory;
@@ -1,30 +1,30 @@
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 linux_1 = __importDefault(require("./linux"));
10
- const mac_1 = __importDefault(require("./mac"));
11
- const messages_1 = require("../messages");
12
- //Create instance of builder depending on platform
13
- function builderFactory(ip, platform, options) {
14
- let builder;
15
- helper_1.validateIp(ip);
16
- if (!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
- builder = windows_1.default(ip, options); //creates and builds commands for windows
21
- }
22
- else if (platform === 'darwin') {
23
- builder = mac_1.default(ip, options); //creates and builds commands for mac
24
- }
25
- else {
26
- builder = linux_1.default(ip, options); //creates and builds commands for linux
27
- }
28
- return builder;
29
- }
30
- exports.default = builderFactory;
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 linux_1 = __importDefault(require("./linux"));
10
+ const mac_1 = __importDefault(require("./mac"));
11
+ const messages_1 = require("../messages");
12
+ //Create instance of builder depending on platform
13
+ function builderFactory(ip, platform, options) {
14
+ let builder;
15
+ (0, helper_1.validateIp)(ip);
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
+ builder = (0, windows_1.default)(ip, options); //creates and builds commands for windows
21
+ }
22
+ else if (platform === 'darwin') {
23
+ builder = (0, mac_1.default)(ip, options); //creates and builds commands for mac
24
+ }
25
+ else {
26
+ builder = (0, linux_1.default)(ip, options); //creates and builds commands for linux
27
+ }
28
+ return builder;
29
+ }
30
+ exports.default = builderFactory;
@@ -1,3 +1,3 @@
1
- import { commandBuilder, extendedPingOptions } from '../types';
2
- declare const linux: (ip: string, options?: extendedPingOptions | undefined) => commandBuilder;
3
- export default linux;
1
+ import { commandBuilder, extendedPingOptions } from '../types';
2
+ declare const linux: (ip: string, options?: extendedPingOptions) => commandBuilder;
3
+ export default linux;
@@ -1,82 +1,82 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const messages_1 = require("../messages");
4
- const process_1 = require("process");
5
- const linux = (ip, options) => {
6
- let defaultNumberOfEchoes = '4';
7
- let args = [];
8
- let buildCommand = {
9
- command: 'ping',
10
- arguments: args
11
- };
12
- //NO Allowing Unsanitized user input into spawn.Checking each param and assigning
13
- if (!options) {
14
- buildCommand.arguments.push('-c', defaultNumberOfEchoes);
15
- args.push(ip);
16
- return buildCommand;
17
- }
18
- if (typeof (options === null || options === void 0 ? void 0 : options.numberOfEchos) === 'number') {
19
- args.push('-c', options.numberOfEchos.toString());
20
- }
21
- else {
22
- args.push('-c', defaultNumberOfEchoes);
23
- }
24
- if (options === null || options === void 0 ? void 0 : options.soDebugOption) {
25
- args.push('-d');
26
- }
27
- if (typeof (options === null || options === void 0 ? void 0 : options.interval) === 'number') {
28
- if (options === null || options === void 0 ? void 0 : options.floodPing) {
29
- args.push('-f');
30
- process_1.emitWarning(messages_1.ERROR_MESSAGES.FLOOD_AND_INTERVAL_ARGS, 'argumentWarning'); //Catch the warning and process it
31
- }
32
- else {
33
- args.push('-i', options === null || options === void 0 ? void 0 : options.interval.toString());
34
- }
35
- }
36
- if (options === null || options === void 0 ? void 0 : options.floodPing) {
37
- if (typeof (options === null || options === void 0 ? void 0 : options.interval) === 'number') {
38
- args.push('-i', options === null || options === void 0 ? void 0 : options.interval.toString());
39
- process_1.emitWarning(messages_1.ERROR_MESSAGES.FLOOD_AND_INTERVAL_ARGS, 'argumentWarning');
40
- }
41
- else {
42
- args.push('-f');
43
- }
44
- }
45
- if (typeof (options === null || options === void 0 ? void 0 : options.interfaceAddress) === 'string') {
46
- args.push('-I', options.interfaceAddress);
47
- }
48
- if (options === null || options === void 0 ? void 0 : options.suppressLoopback) {
49
- args.push('-L');
50
- }
51
- if (typeof (options === null || options === void 0 ? void 0 : options.TTL) === 'number') {
52
- args.push('-t', options.TTL.toString());
53
- }
54
- if (options === null || options === void 0 ? void 0 : options.numeric) {
55
- args.push('-n');
56
- }
57
- if (typeof (options === null || options === void 0 ? void 0 : options.pattern) === 'string') {
58
- args.push('-p', options.pattern);
59
- }
60
- if (options === null || options === void 0 ? void 0 : options.quiet) {
61
- args.push('-q');
62
- }
63
- if (typeof (options === null || options === void 0 ? void 0 : options.bufferSize) === 'number') {
64
- args.push('-s', options.bufferSize.toString());
65
- }
66
- if (typeof (options === null || options === void 0 ? void 0 : options.timeBeforeExit) === 'number') {
67
- args.push('-W', options.timeBeforeExit.toString());
68
- }
69
- if (options === null || options === void 0 ? void 0 : options.verboseOutput) {
70
- args.push('-v');
71
- }
72
- if (typeof (options === null || options === void 0 ? void 0 : options.timeout) === 'number') {
73
- args.push('-w', options.timeout.toString());
74
- }
75
- if (options === null || options === void 0 ? void 0 : options.IPV6) {
76
- buildCommand.command = 'ping6';
77
- }
78
- args.push(ip);
79
- buildCommand.arguments = args;
80
- return buildCommand;
81
- };
82
- exports.default = linux;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const messages_1 = require("../messages");
4
+ const process_1 = require("process");
5
+ const linux = (ip, options) => {
6
+ let defaultNumberOfEchoes = '4';
7
+ let args = [];
8
+ let buildCommand = {
9
+ command: 'ping',
10
+ arguments: args
11
+ };
12
+ //NO Allowing Unsanitized user input into spawn.Checking each param and assigning
13
+ if (!options) {
14
+ buildCommand.arguments.push('-c', defaultNumberOfEchoes);
15
+ args.push(ip);
16
+ return buildCommand;
17
+ }
18
+ if (typeof (options === null || options === void 0 ? void 0 : options.numberOfEchos) === 'number') {
19
+ args.push('-c', options.numberOfEchos.toString());
20
+ }
21
+ else {
22
+ args.push('-c', defaultNumberOfEchoes);
23
+ }
24
+ if (options === null || options === void 0 ? void 0 : options.soDebugOption) {
25
+ args.push('-d');
26
+ }
27
+ if (typeof (options === null || options === void 0 ? void 0 : options.interval) === 'number') {
28
+ if (options === null || options === void 0 ? void 0 : options.floodPing) {
29
+ args.push('-f');
30
+ (0, process_1.emitWarning)(messages_1.ERROR_MESSAGES.FLOOD_AND_INTERVAL_ARGS, 'argumentWarning'); //Catch the warning and process it
31
+ }
32
+ else {
33
+ args.push('-i', options === null || options === void 0 ? void 0 : options.interval.toString());
34
+ }
35
+ }
36
+ if (options === null || options === void 0 ? void 0 : options.floodPing) {
37
+ if (typeof (options === null || options === void 0 ? void 0 : options.interval) === 'number') {
38
+ args.push('-i', options === null || options === void 0 ? void 0 : options.interval.toString());
39
+ (0, process_1.emitWarning)(messages_1.ERROR_MESSAGES.FLOOD_AND_INTERVAL_ARGS, 'argumentWarning');
40
+ }
41
+ else {
42
+ args.push('-f');
43
+ }
44
+ }
45
+ if (typeof (options === null || options === void 0 ? void 0 : options.interfaceAddress) === 'string') {
46
+ args.push('-I', options.interfaceAddress);
47
+ }
48
+ if (options === null || options === void 0 ? void 0 : options.suppressLoopback) {
49
+ args.push('-L');
50
+ }
51
+ if (typeof (options === null || options === void 0 ? void 0 : options.TTL) === 'number') {
52
+ args.push('-t', options.TTL.toString());
53
+ }
54
+ if (options === null || options === void 0 ? void 0 : options.numeric) {
55
+ args.push('-n');
56
+ }
57
+ if (typeof (options === null || options === void 0 ? void 0 : options.pattern) === 'string') {
58
+ args.push('-p', options.pattern);
59
+ }
60
+ if (options === null || options === void 0 ? void 0 : options.quiet) {
61
+ args.push('-q');
62
+ }
63
+ if (typeof (options === null || options === void 0 ? void 0 : options.bufferSize) === 'number') {
64
+ args.push('-s', options.bufferSize.toString());
65
+ }
66
+ if (typeof (options === null || options === void 0 ? void 0 : options.timeBeforeExit) === 'number') {
67
+ args.push('-W', options.timeBeforeExit.toString());
68
+ }
69
+ if (options === null || options === void 0 ? void 0 : options.verboseOutput) {
70
+ args.push('-v');
71
+ }
72
+ if (typeof (options === null || options === void 0 ? void 0 : options.timeout) === 'number') {
73
+ args.push('-w', options.timeout.toString());
74
+ }
75
+ if (options === null || options === void 0 ? void 0 : options.IPV6) {
76
+ buildCommand.command = 'ping6';
77
+ }
78
+ args.push(ip);
79
+ buildCommand.arguments = args;
80
+ return buildCommand;
81
+ };
82
+ exports.default = linux;
@@ -1,3 +1,3 @@
1
- import { commandBuilder, extendedPingOptions } from '../types';
2
- declare const mac: (ip: string, options?: extendedPingOptions | undefined) => commandBuilder;
3
- export default mac;
1
+ import { commandBuilder, extendedPingOptions } from '../types';
2
+ declare const mac: (ip: string, options?: extendedPingOptions) => commandBuilder;
3
+ export default mac;
@@ -1,88 +1,88 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const process_1 = require("process");
4
- const messages_1 = require("../messages");
5
- const mac = (ip, options) => {
6
- let defaultNumberOfEchoes = '4'; //default needed because mac by default has continous ping till we cancel
7
- let args = [];
8
- let buildCommand = {
9
- command: '/sbin/ping',
10
- arguments: args
11
- };
12
- //NO Allowing Unsanitized user input into spawn.Checking each param and assigning
13
- if (!options) {
14
- buildCommand.arguments.push('-c', defaultNumberOfEchoes);
15
- args.push(ip);
16
- return buildCommand;
17
- }
18
- if (typeof (options === null || options === void 0 ? void 0 : options.numberOfEchos) === 'number') {
19
- args.push('-c', options.numberOfEchos.toString());
20
- }
21
- else {
22
- args.push('-c', defaultNumberOfEchoes);
23
- }
24
- if (options === null || options === void 0 ? void 0 : options.soDebugOption) {
25
- args.push('-d');
26
- }
27
- if (typeof (options === null || options === void 0 ? void 0 : options.interval) === 'number') {
28
- if (options === null || options === void 0 ? void 0 : options.floodPing) {
29
- args.push('-f');
30
- process_1.emitWarning(messages_1.ERROR_MESSAGES.FLOOD_AND_INTERVAL_ARGS, 'argumentWarning');
31
- }
32
- else {
33
- args.push('-i', options === null || options === void 0 ? void 0 : options.interval.toString());
34
- }
35
- }
36
- if (options === null || options === void 0 ? void 0 : options.floodPing) {
37
- if (typeof (options === null || options === void 0 ? void 0 : options.interval) === 'number') {
38
- args.push('-i', options === null || options === void 0 ? void 0 : options.interval.toString());
39
- }
40
- else {
41
- args.push('-f');
42
- process_1.emitWarning(messages_1.ERROR_MESSAGES.FLOOD_AND_INTERVAL_ARGS, 'argumentWarning');
43
- }
44
- }
45
- if (typeof (options === null || options === void 0 ? void 0 : options.interfaceAddress) === 'string') {
46
- args.push('-I', options.interfaceAddress);
47
- }
48
- if (options === null || options === void 0 ? void 0 : options.suppressLoopback) {
49
- args.push('-L');
50
- }
51
- if (typeof (options === null || options === void 0 ? void 0 : options.TTL) === 'number') {
52
- args.push('-m', options.TTL.toString()); //change to -t for linux
53
- }
54
- if (options.doNotFragment) {
55
- args.push('-D');
56
- }
57
- if (options === null || options === void 0 ? void 0 : options.numeric) {
58
- args.push('-n');
59
- }
60
- if (typeof (options === null || options === void 0 ? void 0 : options.pattern) === 'string') {
61
- args.push('-p', options.pattern);
62
- }
63
- if (options === null || options === void 0 ? void 0 : options.quiet) {
64
- args.push('-q');
65
- }
66
- if (typeof (options === null || options === void 0 ? void 0 : options.srcAddr) === 'string') {
67
- args.push('-S', options.srcAddr); //Delete for Linux
68
- }
69
- if (typeof (options === null || options === void 0 ? void 0 : options.bufferSize) === 'number') {
70
- args.push('-s', options.bufferSize.toString());
71
- }
72
- if (typeof (options === null || options === void 0 ? void 0 : options.timeBeforeExit) === 'number') {
73
- args.push('-t', options.timeBeforeExit.toString()); //change to -w for linux
74
- }
75
- if (options === null || options === void 0 ? void 0 : options.verboseOutput) {
76
- args.push('-v');
77
- }
78
- if (typeof (options === null || options === void 0 ? void 0 : options.timeout) === 'number') {
79
- args.push('-W', (options.timeout * 1000).toString());
80
- }
81
- if (options === null || options === void 0 ? void 0 : options.IPV6) {
82
- buildCommand.command = '/sbin/ping6';
83
- }
84
- args.push(ip);
85
- buildCommand.arguments = args;
86
- return buildCommand;
87
- };
88
- exports.default = mac;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const process_1 = require("process");
4
+ const messages_1 = require("../messages");
5
+ const mac = (ip, options) => {
6
+ let defaultNumberOfEchoes = '4'; //default needed because mac by default has continous ping till we cancel
7
+ let args = [];
8
+ let buildCommand = {
9
+ command: '/sbin/ping',
10
+ arguments: args
11
+ };
12
+ //NO Allowing Unsanitized user input into spawn.Checking each param and assigning
13
+ if (!options) {
14
+ buildCommand.arguments.push('-c', defaultNumberOfEchoes);
15
+ args.push(ip);
16
+ return buildCommand;
17
+ }
18
+ if (typeof (options === null || options === void 0 ? void 0 : options.numberOfEchos) === 'number') {
19
+ args.push('-c', options.numberOfEchos.toString());
20
+ }
21
+ else {
22
+ args.push('-c', defaultNumberOfEchoes);
23
+ }
24
+ if (options === null || options === void 0 ? void 0 : options.soDebugOption) {
25
+ args.push('-d');
26
+ }
27
+ if (typeof (options === null || options === void 0 ? void 0 : options.interval) === 'number') {
28
+ if (options === null || options === void 0 ? void 0 : options.floodPing) {
29
+ args.push('-f');
30
+ (0, process_1.emitWarning)(messages_1.ERROR_MESSAGES.FLOOD_AND_INTERVAL_ARGS, 'argumentWarning');
31
+ }
32
+ else {
33
+ args.push('-i', options === null || options === void 0 ? void 0 : options.interval.toString());
34
+ }
35
+ }
36
+ if (options === null || options === void 0 ? void 0 : options.floodPing) {
37
+ if (typeof (options === null || options === void 0 ? void 0 : options.interval) === 'number') {
38
+ args.push('-i', options === null || options === void 0 ? void 0 : options.interval.toString());
39
+ }
40
+ else {
41
+ args.push('-f');
42
+ (0, process_1.emitWarning)(messages_1.ERROR_MESSAGES.FLOOD_AND_INTERVAL_ARGS, 'argumentWarning');
43
+ }
44
+ }
45
+ if (typeof (options === null || options === void 0 ? void 0 : options.interfaceAddress) === 'string') {
46
+ args.push('-I', options.interfaceAddress);
47
+ }
48
+ if (options === null || options === void 0 ? void 0 : options.suppressLoopback) {
49
+ args.push('-L');
50
+ }
51
+ if (typeof (options === null || options === void 0 ? void 0 : options.TTL) === 'number') {
52
+ args.push('-m', options.TTL.toString()); //change to -t for linux
53
+ }
54
+ if (options.doNotFragment) {
55
+ args.push('-D');
56
+ }
57
+ if (options === null || options === void 0 ? void 0 : options.numeric) {
58
+ args.push('-n');
59
+ }
60
+ if (typeof (options === null || options === void 0 ? void 0 : options.pattern) === 'string') {
61
+ args.push('-p', options.pattern);
62
+ }
63
+ if (options === null || options === void 0 ? void 0 : options.quiet) {
64
+ args.push('-q');
65
+ }
66
+ if (typeof (options === null || options === void 0 ? void 0 : options.srcAddr) === 'string') {
67
+ args.push('-S', options.srcAddr); //Delete for Linux
68
+ }
69
+ if (typeof (options === null || options === void 0 ? void 0 : options.bufferSize) === 'number') {
70
+ args.push('-s', options.bufferSize.toString());
71
+ }
72
+ if (typeof (options === null || options === void 0 ? void 0 : options.timeBeforeExit) === 'number') {
73
+ args.push('-t', options.timeBeforeExit.toString()); //change to -w for linux
74
+ }
75
+ if (options === null || options === void 0 ? void 0 : options.verboseOutput) {
76
+ args.push('-v');
77
+ }
78
+ if (typeof (options === null || options === void 0 ? void 0 : options.timeout) === 'number') {
79
+ args.push('-W', (options.timeout * 1000).toString());
80
+ }
81
+ if (options === null || options === void 0 ? void 0 : options.IPV6) {
82
+ buildCommand.command = '/sbin/ping6';
83
+ }
84
+ args.push(ip);
85
+ buildCommand.arguments = args;
86
+ return buildCommand;
87
+ };
88
+ exports.default = mac;
@@ -1,3 +1,3 @@
1
- import { commandBuilder, extendedPingOptions } from '../types';
2
- declare const windows: (ip: string, options?: extendedPingOptions | undefined) => commandBuilder;
3
- export default windows;
1
+ import { commandBuilder, extendedPingOptions } from '../types';
2
+ declare const windows: (ip: string, options?: extendedPingOptions) => commandBuilder;
3
+ export default windows;