pingman 1.1.5 → 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 +21 -21
- package/dist/src/builder/builder.d.ts +3 -3
- package/dist/src/builder/builder.js +30 -30
- package/dist/src/builder/linux.d.ts +3 -3
- package/dist/src/builder/linux.js +82 -82
- package/dist/src/builder/mac.d.ts +3 -3
- package/dist/src/builder/mac.js +88 -88
- package/dist/src/builder/windows.d.ts +3 -3
- package/dist/src/builder/windows.js +93 -93
- package/dist/src/errors.d.ts +10 -10
- package/dist/src/errors.js +25 -24
- package/dist/src/helper.d.ts +2 -2
- package/dist/src/helper.js +33 -32
- package/dist/src/index.d.ts +4 -4
- package/dist/src/index.js +56 -40
- package/dist/src/log.d.ts +7 -7
- package/dist/src/log.js +25 -25
- package/dist/src/messages.d.ts +9 -9
- package/dist/src/messages.js +12 -11
- package/dist/src/parser/linux.d.ts +7 -7
- package/dist/src/parser/linux.js +30 -30
- package/dist/src/parser/mac.d.ts +11 -11
- package/dist/src/parser/mac.js +46 -46
- package/dist/src/parser/parser.interface.d.ts +8 -8
- package/dist/src/parser/parser.interface.js +2 -2
- package/dist/src/parser/parserFactory.d.ts +3 -3
- package/dist/src/parser/parserFactory.js +122 -122
- package/dist/src/parser/windows.d.ts +13 -13
- package/dist/src/parser/windows.js +110 -110
- package/dist/src/ping.d.ts +3 -3
- package/dist/src/ping.js +22 -22
- package/dist/src/types.d.ts +44 -44
- package/dist/src/types.js +2 -2
- package/package.json +4 -5
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const process_1 = require("process");
|
|
4
|
-
const messages_1 = require("../messages");
|
|
5
|
-
const windows = (ip, options) => {
|
|
6
|
-
let args = [];
|
|
7
|
-
const windowsRootPath = process.env.SystemRoot + '/system32/ping.exe';
|
|
8
|
-
//NO Allowing Unsanitized user input into spawn.Checking each param and assigning
|
|
9
|
-
if (!options) {
|
|
10
|
-
args.push(ip);
|
|
11
|
-
return {
|
|
12
|
-
command: windowsRootPath,
|
|
13
|
-
arguments: args
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
if (options === null || options === void 0 ? void 0 : options.numeric) {
|
|
18
|
-
args.push('-a');
|
|
19
|
-
}
|
|
20
|
-
if (typeof (options === null || options === void 0 ? void 0 : options.numberOfEchos) === 'number') {
|
|
21
|
-
args.push('-n', options.numberOfEchos.toString());
|
|
22
|
-
}
|
|
23
|
-
if (typeof (options === null || options === void 0 ? void 0 : options.bufferSize) === 'number') {
|
|
24
|
-
args.push('-l', options.bufferSize.toString());
|
|
25
|
-
}
|
|
26
|
-
if (typeof (options === null || options === void 0 ? void 0 : options.TTL) === 'number') {
|
|
27
|
-
args.push('-i', options.TTL.toString());
|
|
28
|
-
}
|
|
29
|
-
if (typeof (options === null || options === void 0 ? void 0 : options.timeout) === 'number') {
|
|
30
|
-
args.push('-w', (options.timeout * 1000).toString());
|
|
31
|
-
}
|
|
32
|
-
args.push(...(checkForIpV4SpecificFields(options)));
|
|
33
|
-
args.push(...(checkForIpV6SpecificFields(options)));
|
|
34
|
-
args.push(ip);
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
command: windowsRootPath,
|
|
38
|
-
arguments: args
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
//Checking for windows IPV4 fields as per official documentation
|
|
42
|
-
function checkForIpV4SpecificFields(options) {
|
|
43
|
-
let optionsUsed = "";
|
|
44
|
-
let args = [];
|
|
45
|
-
if (options === null || options === void 0 ? void 0 : options.IPV4) {
|
|
46
|
-
args.push('-4');
|
|
47
|
-
if (options.doNotFragment) {
|
|
48
|
-
args.push('-f');
|
|
49
|
-
}
|
|
50
|
-
if (typeof (options === null || options === void 0 ? void 0 : options.recordRouteHops) === 'number') {
|
|
51
|
-
args.push('-r', options.recordRouteHops.toString());
|
|
52
|
-
}
|
|
53
|
-
if (typeof (options === null || options === void 0 ? void 0 : options.hopTimestamp) === 'number') {
|
|
54
|
-
args.push('-s', options.hopTimestamp.toString());
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
if (options.doNotFragment) {
|
|
59
|
-
optionsUsed = optionsUsed.concat(',', options.doNotFragment.toString());
|
|
60
|
-
}
|
|
61
|
-
if (options.recordRouteHops) {
|
|
62
|
-
optionsUsed = optionsUsed.concat(',', options.recordRouteHops.toString());
|
|
63
|
-
}
|
|
64
|
-
if (options.hopTimestamp) {
|
|
65
|
-
optionsUsed = optionsUsed.concat(',', options.hopTimestamp.toString());
|
|
66
|
-
}
|
|
67
|
-
if (optionsUsed.length > 0) {
|
|
68
|
-
process_1.emitWarning(messages_1.ERROR_MESSAGES.ENABLE_IPV4_EXPLICIT.replace('commands', optionsUsed), 'IPV4OnlyWarning');
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return args;
|
|
72
|
-
}
|
|
73
|
-
//Checking for windows IPV6 fields as per official documentation
|
|
74
|
-
function checkForIpV6SpecificFields(options) {
|
|
75
|
-
let optionsUsed = "";
|
|
76
|
-
let args = [];
|
|
77
|
-
if (options === null || options === void 0 ? void 0 : options.IPV6) {
|
|
78
|
-
args.push('-6');
|
|
79
|
-
if (options.srcAddr) {
|
|
80
|
-
args.push('-S', options.srcAddr);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
if (typeof options.srcAddr === 'string') {
|
|
85
|
-
optionsUsed = optionsUsed.concat(',', options.srcAddr);
|
|
86
|
-
}
|
|
87
|
-
if (optionsUsed.length > 0) {
|
|
88
|
-
process_1.emitWarning(messages_1.ERROR_MESSAGES.ENABLE_IPV6_EXPLICIT.replace('commands', optionsUsed), 'IPV6OnlyWarning');
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return args;
|
|
92
|
-
}
|
|
93
|
-
exports.default = windows;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const process_1 = require("process");
|
|
4
|
+
const messages_1 = require("../messages");
|
|
5
|
+
const windows = (ip, options) => {
|
|
6
|
+
let args = [];
|
|
7
|
+
const windowsRootPath = process.env.SystemRoot + '/system32/ping.exe';
|
|
8
|
+
//NO Allowing Unsanitized user input into spawn.Checking each param and assigning
|
|
9
|
+
if (!options) {
|
|
10
|
+
args.push(ip);
|
|
11
|
+
return {
|
|
12
|
+
command: windowsRootPath,
|
|
13
|
+
arguments: args
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
if (options === null || options === void 0 ? void 0 : options.numeric) {
|
|
18
|
+
args.push('-a');
|
|
19
|
+
}
|
|
20
|
+
if (typeof (options === null || options === void 0 ? void 0 : options.numberOfEchos) === 'number') {
|
|
21
|
+
args.push('-n', options.numberOfEchos.toString());
|
|
22
|
+
}
|
|
23
|
+
if (typeof (options === null || options === void 0 ? void 0 : options.bufferSize) === 'number') {
|
|
24
|
+
args.push('-l', options.bufferSize.toString());
|
|
25
|
+
}
|
|
26
|
+
if (typeof (options === null || options === void 0 ? void 0 : options.TTL) === 'number') {
|
|
27
|
+
args.push('-i', options.TTL.toString());
|
|
28
|
+
}
|
|
29
|
+
if (typeof (options === null || options === void 0 ? void 0 : options.timeout) === 'number') {
|
|
30
|
+
args.push('-w', (options.timeout * 1000).toString());
|
|
31
|
+
}
|
|
32
|
+
args.push(...(checkForIpV4SpecificFields(options)));
|
|
33
|
+
args.push(...(checkForIpV6SpecificFields(options)));
|
|
34
|
+
args.push(ip);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
command: windowsRootPath,
|
|
38
|
+
arguments: args
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
//Checking for windows IPV4 fields as per official documentation
|
|
42
|
+
function checkForIpV4SpecificFields(options) {
|
|
43
|
+
let optionsUsed = "";
|
|
44
|
+
let args = [];
|
|
45
|
+
if (options === null || options === void 0 ? void 0 : options.IPV4) {
|
|
46
|
+
args.push('-4');
|
|
47
|
+
if (options.doNotFragment) {
|
|
48
|
+
args.push('-f');
|
|
49
|
+
}
|
|
50
|
+
if (typeof (options === null || options === void 0 ? void 0 : options.recordRouteHops) === 'number') {
|
|
51
|
+
args.push('-r', options.recordRouteHops.toString());
|
|
52
|
+
}
|
|
53
|
+
if (typeof (options === null || options === void 0 ? void 0 : options.hopTimestamp) === 'number') {
|
|
54
|
+
args.push('-s', options.hopTimestamp.toString());
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
if (options.doNotFragment) {
|
|
59
|
+
optionsUsed = optionsUsed.concat(',', options.doNotFragment.toString());
|
|
60
|
+
}
|
|
61
|
+
if (options.recordRouteHops) {
|
|
62
|
+
optionsUsed = optionsUsed.concat(',', options.recordRouteHops.toString());
|
|
63
|
+
}
|
|
64
|
+
if (options.hopTimestamp) {
|
|
65
|
+
optionsUsed = optionsUsed.concat(',', options.hopTimestamp.toString());
|
|
66
|
+
}
|
|
67
|
+
if (optionsUsed.length > 0) {
|
|
68
|
+
(0, process_1.emitWarning)(messages_1.ERROR_MESSAGES.ENABLE_IPV4_EXPLICIT.replace('commands', optionsUsed), 'IPV4OnlyWarning');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return args;
|
|
72
|
+
}
|
|
73
|
+
//Checking for windows IPV6 fields as per official documentation
|
|
74
|
+
function checkForIpV6SpecificFields(options) {
|
|
75
|
+
let optionsUsed = "";
|
|
76
|
+
let args = [];
|
|
77
|
+
if (options === null || options === void 0 ? void 0 : options.IPV6) {
|
|
78
|
+
args.push('-6');
|
|
79
|
+
if (options.srcAddr) {
|
|
80
|
+
args.push('-S', options.srcAddr);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
if (typeof options.srcAddr === 'string') {
|
|
85
|
+
optionsUsed = optionsUsed.concat(',', options.srcAddr);
|
|
86
|
+
}
|
|
87
|
+
if (optionsUsed.length > 0) {
|
|
88
|
+
(0, process_1.emitWarning)(messages_1.ERROR_MESSAGES.ENABLE_IPV6_EXPLICIT.replace('commands', optionsUsed), 'IPV6OnlyWarning');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return args;
|
|
92
|
+
}
|
|
93
|
+
exports.default = windows;
|
package/dist/src/errors.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export declare class pingError extends Error {
|
|
2
|
-
code?: string;
|
|
3
|
-
constructor(message: string, code?: string);
|
|
4
|
-
}
|
|
5
|
-
export declare class ipError extends pingError {
|
|
6
|
-
constructor(message: string);
|
|
7
|
-
}
|
|
8
|
-
export declare class supportedError extends pingError {
|
|
9
|
-
constructor(message: string);
|
|
10
|
-
}
|
|
1
|
+
export declare class pingError extends Error {
|
|
2
|
+
code?: string;
|
|
3
|
+
constructor(message: string, code?: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class ipError extends pingError {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class supportedError extends pingError {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
package/dist/src/errors.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.supportedError = exports.ipError = exports.pingError = void 0;
|
|
4
|
+
class pingError extends Error {
|
|
5
|
+
constructor(message, code) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'pingError';
|
|
8
|
+
this.code = code;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.pingError = pingError;
|
|
12
|
+
class ipError extends pingError {
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = 'ipError';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ipError = ipError;
|
|
19
|
+
class supportedError extends pingError {
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = 'platformNotSupportedError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.supportedError = supportedError;
|
package/dist/src/helper.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function validateIp(ip: string): boolean;
|
|
2
|
-
export declare function isPlatformSupported(platform: string): boolean;
|
|
1
|
+
export declare function validateIp(ip: string): boolean;
|
|
2
|
+
export declare function isPlatformSupported(platform: string): boolean;
|
package/dist/src/helper.js
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPlatformSupported = exports.validateIp = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
const messages_1 = require("./messages");
|
|
6
|
+
//Function to validate ip given as input
|
|
7
|
+
function validateIp(ip) {
|
|
8
|
+
if (!ip) {
|
|
9
|
+
throw new errors_1.ipError(messages_1.ERROR_MESSAGES.IP_NOT_PROVIDED);
|
|
10
|
+
}
|
|
11
|
+
//Regex for IPV4 and IPV6 addresses
|
|
12
|
+
if (!/((^\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*$))/.test(ip)) {
|
|
13
|
+
//Regex for domain names
|
|
14
|
+
if (!/^([A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)?(?:\.[a-zA-Z]{2,})+/.test(ip))
|
|
15
|
+
throw new errors_1.ipError(messages_1.ERROR_MESSAGES.IP_NOT_VALID);
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
exports.validateIp = validateIp;
|
|
20
|
+
//Function to check if platform is one of the three supported
|
|
21
|
+
function isPlatformSupported(platform) {
|
|
22
|
+
let supportedPlatform = platformsSupported.some((supportedPlatform) => {
|
|
23
|
+
return platform === supportedPlatform;
|
|
24
|
+
});
|
|
25
|
+
return supportedPlatform;
|
|
26
|
+
}
|
|
27
|
+
exports.isPlatformSupported = isPlatformSupported;
|
|
28
|
+
//current platforms supported - TO-DO add more after further testing
|
|
29
|
+
const platformsSupported = [
|
|
30
|
+
'win32',
|
|
31
|
+
'darwin',
|
|
32
|
+
'linux'
|
|
33
|
+
];
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { extendedPingOptions, pingResponse } from './types';
|
|
2
|
-
declare const ping: (ipAddress: string, pingOptions?: extendedPingOptions
|
|
3
|
-
export default ping;
|
|
4
|
-
export { extendedPingOptions, pingOptions, pingResponse } from './types';
|
|
1
|
+
import { extendedPingOptions, pingResponse } from './types';
|
|
2
|
+
declare const ping: (ipAddress: string, pingOptions?: extendedPingOptions) => Promise<pingResponse>;
|
|
3
|
+
export default ping;
|
|
4
|
+
export { extendedPingOptions, pingOptions, pingResponse } from './types';
|
package/dist/src/index.js
CHANGED
|
@@ -1,40 +1,56 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const builder_1 = __importDefault(require("./builder/builder"));
|
|
30
|
+
const os = __importStar(require("os"));
|
|
31
|
+
const log_1 = __importDefault(require("./log"));
|
|
32
|
+
const ping_1 = __importDefault(require("./ping"));
|
|
33
|
+
const parserFactory_1 = __importDefault(require("./parser/parserFactory"));
|
|
34
|
+
//the initial ping function call
|
|
35
|
+
const ping = async (ipAddress, pingOptions) => {
|
|
36
|
+
let logger;
|
|
37
|
+
//create a log file if logToFile option is enabled
|
|
38
|
+
logger = new log_1.default((pingOptions === null || pingOptions === void 0 ? void 0 : pingOptions.logFilePath) || 'log.txt', (pingOptions === null || pingOptions === void 0 ? void 0 : pingOptions.logToFile) || false);
|
|
39
|
+
try {
|
|
40
|
+
const platform = os.platform();
|
|
41
|
+
const builtCommand = (0, builder_1.default)(ipAddress, platform, pingOptions);
|
|
42
|
+
logger.writeToLogFile(JSON.stringify(builtCommand));
|
|
43
|
+
const pingOutput = await (0, ping_1.default)(builtCommand);
|
|
44
|
+
const parsedOutput = (0, parserFactory_1.default)(platform, pingOutput, pingOptions);
|
|
45
|
+
logger.writeToLogFile(JSON.stringify(parsedOutput.output));
|
|
46
|
+
return parsedOutput;
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
logger.writeToLogFile(error);
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.default = ping;
|
|
54
|
+
// For CommonJS default export support
|
|
55
|
+
module.exports = ping;
|
|
56
|
+
module.exports.default = ping;
|
package/dist/src/log.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
declare class Logger {
|
|
2
|
-
logFile: any;
|
|
3
|
-
enabledLogging: boolean;
|
|
4
|
-
constructor(logFilePath: string, enabledLogging: boolean);
|
|
5
|
-
writeToLogFile(message: string): Promise<void>;
|
|
6
|
-
}
|
|
7
|
-
export default Logger;
|
|
1
|
+
declare class Logger {
|
|
2
|
+
logFile: any;
|
|
3
|
+
enabledLogging: boolean;
|
|
4
|
+
constructor(logFilePath: string, enabledLogging: boolean);
|
|
5
|
+
writeToLogFile(message: string): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
export default Logger;
|
package/dist/src/log.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
//class for logging to file
|
|
5
|
-
class Logger {
|
|
6
|
-
//constructor to open a write stream if logging is enabled
|
|
7
|
-
constructor(logFilePath, enabledLogging) {
|
|
8
|
-
let fullPath = logFilePath;
|
|
9
|
-
if (enabledLogging) {
|
|
10
|
-
this.logFile = fs.createWriteStream(fullPath, { flags: 'a+', encoding: 'utf8' });
|
|
11
|
-
this.enabledLogging = true;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
this.logFile = {};
|
|
15
|
-
this.enabledLogging = false;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
//write to file
|
|
19
|
-
async writeToLogFile(message) {
|
|
20
|
-
if (this.enabledLogging) {
|
|
21
|
-
this.logFile.write(message, 'utf8');
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.default = Logger;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
//class for logging to file
|
|
5
|
+
class Logger {
|
|
6
|
+
//constructor to open a write stream if logging is enabled
|
|
7
|
+
constructor(logFilePath, enabledLogging) {
|
|
8
|
+
let fullPath = logFilePath;
|
|
9
|
+
if (enabledLogging) {
|
|
10
|
+
this.logFile = fs.createWriteStream(fullPath, { flags: 'a+', encoding: 'utf8' });
|
|
11
|
+
this.enabledLogging = true;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
this.logFile = {};
|
|
15
|
+
this.enabledLogging = false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//write to file
|
|
19
|
+
async writeToLogFile(message) {
|
|
20
|
+
if (this.enabledLogging) {
|
|
21
|
+
this.logFile.write(message, 'utf8');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.default = Logger;
|
package/dist/src/messages.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export declare const ERROR_MESSAGES: {
|
|
2
|
-
IP_NOT_PROVIDED: string;
|
|
3
|
-
IP_NOT_VALID: string;
|
|
4
|
-
PLATFORM_NOT_SUPPORTED: string;
|
|
5
|
-
ENABLE_IPV4_EXPLICIT: string;
|
|
6
|
-
ENABLE_IPV6_EXPLICIT: string;
|
|
7
|
-
FLOOD_AND_INTERVAL_ARGS: string;
|
|
8
|
-
GENERAL_PING_ERROR: string;
|
|
9
|
-
};
|
|
1
|
+
export declare const ERROR_MESSAGES: {
|
|
2
|
+
IP_NOT_PROVIDED: string;
|
|
3
|
+
IP_NOT_VALID: string;
|
|
4
|
+
PLATFORM_NOT_SUPPORTED: string;
|
|
5
|
+
ENABLE_IPV4_EXPLICIT: string;
|
|
6
|
+
ENABLE_IPV6_EXPLICIT: string;
|
|
7
|
+
FLOOD_AND_INTERVAL_ARGS: string;
|
|
8
|
+
GENERAL_PING_ERROR: string;
|
|
9
|
+
};
|
package/dist/src/messages.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ERROR_MESSAGES =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERROR_MESSAGES = void 0;
|
|
4
|
+
exports.ERROR_MESSAGES = {
|
|
5
|
+
IP_NOT_PROVIDED: 'IP is not available',
|
|
6
|
+
IP_NOT_VALID: 'Given IP address is not valid',
|
|
7
|
+
PLATFORM_NOT_SUPPORTED: 'Platform platform is not supported',
|
|
8
|
+
ENABLE_IPV4_EXPLICIT: 'Command(s) commands only work with ipv4. Please specify IPV4 param explicitily to enable these',
|
|
9
|
+
ENABLE_IPV6_EXPLICIT: 'Command(s) commands only work with ipv6. Please specify IPV6 param explicitily to enable these',
|
|
10
|
+
FLOOD_AND_INTERVAL_ARGS: 'The flood(-f) option is incompatible with interval(-i) option.Will use flood option',
|
|
11
|
+
GENERAL_PING_ERROR: 'Error while running ping with command cmd and arguments args',
|
|
12
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import mac from "./mac";
|
|
2
|
-
import { pingResponse, extendedPingOptions } from "../types";
|
|
3
|
-
declare class linux extends mac {
|
|
4
|
-
constructor(response: pingResponse, options?: extendedPingOptions);
|
|
5
|
-
processHeader(line: string): void;
|
|
6
|
-
}
|
|
7
|
-
export default linux;
|
|
1
|
+
import mac from "./mac";
|
|
2
|
+
import { pingResponse, extendedPingOptions } from "../types";
|
|
3
|
+
declare class linux extends mac {
|
|
4
|
+
constructor(response: pingResponse, options?: extendedPingOptions);
|
|
5
|
+
processHeader(line: string): void;
|
|
6
|
+
}
|
|
7
|
+
export default linux;
|
package/dist/src/parser/linux.js
CHANGED
|
@@ -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 mac_1 = __importDefault(require("./mac"));
|
|
7
|
-
//extends mac as body and footer identical for mac and linux.Can use mac functions
|
|
8
|
-
class linux extends mac_1.default {
|
|
9
|
-
constructor(response, options) {
|
|
10
|
-
super(response, options);
|
|
11
|
-
}
|
|
12
|
-
processHeader(line) {
|
|
13
|
-
// Get host and numeric_host
|
|
14
|
-
let tokens = line.split(' ');
|
|
15
|
-
let isProbablyIPv4 = tokens[1].indexOf('(') === -1;
|
|
16
|
-
if (isProbablyIPv4) {
|
|
17
|
-
this.response.host = tokens[1];
|
|
18
|
-
this.response.numericHost = tokens[2].slice(1, -1);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
// Normalise into either a 2 or 3 element array
|
|
22
|
-
let foundAddresses = tokens.slice(1, -3).join('').match(/([^\s()]+)/g);
|
|
23
|
-
if (foundAddresses) {
|
|
24
|
-
this.response.host = foundAddresses.shift();
|
|
25
|
-
this.response.numericHost = foundAddresses.pop();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.default = linux;
|
|
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 mac_1 = __importDefault(require("./mac"));
|
|
7
|
+
//extends mac as body and footer identical for mac and linux.Can use mac functions
|
|
8
|
+
class linux extends mac_1.default {
|
|
9
|
+
constructor(response, options) {
|
|
10
|
+
super(response, options);
|
|
11
|
+
}
|
|
12
|
+
processHeader(line) {
|
|
13
|
+
// Get host and numeric_host
|
|
14
|
+
let tokens = line.split(' ');
|
|
15
|
+
let isProbablyIPv4 = tokens[1].indexOf('(') === -1;
|
|
16
|
+
if (isProbablyIPv4) {
|
|
17
|
+
this.response.host = tokens[1];
|
|
18
|
+
this.response.numericHost = tokens[2].slice(1, -1);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
// Normalise into either a 2 or 3 element array
|
|
22
|
+
let foundAddresses = tokens.slice(1, -3).join('').match(/([^\s()]+)/g);
|
|
23
|
+
if (foundAddresses) {
|
|
24
|
+
this.response.host = foundAddresses.shift();
|
|
25
|
+
this.response.numericHost = foundAddresses.pop();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.default = linux;
|