pingman 2.0.0 → 2.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/README.md +211 -192
- package/dist/src/builder/builder.d.ts +3 -3
- package/dist/src/builder/builder.js +31 -30
- package/dist/src/builder/builder.js.map +1 -0
- package/dist/src/builder/linux.d.ts +3 -3
- package/dist/src/builder/linux.js +83 -82
- package/dist/src/builder/linux.js.map +1 -0
- package/dist/src/builder/mac.d.ts +3 -3
- package/dist/src/builder/mac.js +89 -88
- package/dist/src/builder/mac.js.map +1 -0
- package/dist/src/builder/windows.d.ts +3 -3
- package/dist/src/builder/windows.js +94 -93
- package/dist/src/builder/windows.js.map +1 -0
- package/dist/src/errors.d.ts +10 -10
- package/dist/src/errors.js +26 -25
- package/dist/src/errors.js.map +1 -0
- package/dist/src/helper.d.ts +2 -2
- package/dist/src/helper.js +34 -33
- package/dist/src/helper.js.map +1 -0
- package/dist/src/index.d.ts +4 -4
- package/dist/src/index.js +57 -56
- package/dist/src/index.js.map +1 -0
- package/dist/src/log.d.ts +7 -7
- package/dist/src/log.js +26 -25
- package/dist/src/log.js.map +1 -0
- package/dist/src/messages.d.ts +9 -9
- package/dist/src/messages.js +13 -12
- package/dist/src/messages.js.map +1 -0
- package/dist/src/parser/clonePingResponse.d.ts +3 -0
- package/dist/src/parser/clonePingResponse.js +21 -0
- package/dist/src/parser/clonePingResponse.js.map +1 -0
- package/dist/src/parser/linux.d.ts +7 -7
- package/dist/src/parser/linux.js +31 -30
- package/dist/src/parser/linux.js.map +1 -0
- package/dist/src/parser/mac.d.ts +11 -11
- package/dist/src/parser/mac.js +47 -46
- package/dist/src/parser/mac.js.map +1 -0
- package/dist/src/parser/parser.interface.d.ts +8 -8
- package/dist/src/parser/parser.interface.js +3 -2
- package/dist/src/parser/parser.interface.js.map +1 -0
- package/dist/src/parser/parserFactory.d.ts +3 -3
- package/dist/src/parser/parserFactory.js +125 -122
- package/dist/src/parser/parserFactory.js.map +1 -0
- package/dist/src/parser/windows.d.ts +13 -13
- package/dist/src/parser/windows.js +111 -110
- package/dist/src/parser/windows.js.map +1 -0
- package/dist/src/ping.d.ts +3 -3
- package/dist/src/ping.js +23 -22
- package/dist/src/ping.js.map +1 -0
- package/dist/src/types.d.ts +44 -44
- package/dist/src/types.js +3 -2
- package/dist/src/types.js.map +1 -0
- package/package.json +58 -58
package/dist/src/errors.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
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;
|
|
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;
|
|
26
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAU,SAAQ,KAAK;IAEhC,YAAY,OAAe,EAAE,IAAa;QACtC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AAPD,8BAOC;AAED,MAAa,OAAQ,SAAQ,SAAS;IAClC,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;IAC1B,CAAC;CACJ;AALD,0BAKC;AAED,MAAa,cAAe,SAAQ,SAAS;IACzC,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC5C,CAAC;CACJ;AALD,wCAKC"}
|
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,33 +1,34 @@
|
|
|
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,})
|
|
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
|
-
];
|
|
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
|
+
];
|
|
34
|
+
//# sourceMappingURL=helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../src/helper.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAClC,yCAA2C;AAE3C,wCAAwC;AACxC,SAAgB,UAAU,CAAC,EAAU;IACjC,IAAI,CAAC,EAAE,EAAE;QACL,MAAM,IAAI,gBAAO,CAAC,yBAAc,CAAC,eAAe,CAAC,CAAC;KACrD;IACD,mCAAmC;IACnC,IAAI,CAAC,irCAAirC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;QAC7rC,wBAAwB;QACxB,IAAG,CAAC,uEAAuE,CAAC,IAAI,CAAC,EAAE,CAAC;YACpF,MAAM,IAAI,gBAAO,CAAC,yBAAc,CAAC,YAAY,CAAC,CAAC;KAClD;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAXD,gCAWC;AAED,6DAA6D;AAC7D,SAAgB,mBAAmB,CAAC,QAAgB;IAChD,IAAI,iBAAiB,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC,iBAAiB,EAAE,EAAE;QAClE,OAAO,QAAQ,KAAK,iBAAiB,CAAA;IACzC,CAAC,CAAC,CAAC;IACH,OAAO,iBAAiB,CAAC;AAC7B,CAAC;AALD,kDAKC;AAED,oEAAoE;AACpE,MAAM,kBAAkB,GAAG;IACvB,OAAO;IACP,QAAQ;IACR,OAAO;CACV,CAAA"}
|
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) => Promise<pingResponse>;
|
|
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,56 +1,57 @@
|
|
|
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;
|
|
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;
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gEAA8C;AAC9C,uCAAwB;AACxB,gDAA0B;AAC1B,kDAA4B;AAC5B,2EAAkD;AAElD,gCAAgC;AAChC,MAAM,IAAI,GAAG,KAAK,EAAE,SAAiB,EAAE,WAAiC,EAAE,EAAE;IACxE,IAAI,MAAc,CAAC;IACnB,kDAAkD;IAClD,MAAM,GAAG,IAAI,aAAM,CAAC,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,WAAW,KAAI,SAAS,EAAE,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,SAAS,KAAI,KAAK,CAAC,CAAC;IAC5F,IAAI;QACA,MAAM,QAAQ,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;QAC/B,MAAM,YAAY,GAAmB,IAAA,iBAAc,EAAC,SAAS,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;QACtF,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;QACpD,MAAM,UAAU,GAAc,MAAM,IAAA,cAAO,EAAC,YAAY,CAAC,CAAC;QAC1D,MAAM,YAAY,GAAiB,IAAA,uBAAa,EAAC,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;QACpF,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;QAC3D,OAAO,YAAY,CAAC;KACvB;IAAC,OAAO,KAAK,EAAE;QACZ,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC7B,MAAM,KAAK,CAAC;KACf;AACL,CAAC,CAAA;AAED,kBAAe,IAAI,CAAC;AACpB,sCAAsC;AACtC,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;AACtB,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC"}
|
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,26 @@
|
|
|
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;
|
|
26
|
+
//# sourceMappingURL=log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/log.ts"],"names":[],"mappings":";;AAAA,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzB,2BAA2B;AAC3B,MAAM,MAAM;IAIR,0DAA0D;IAC1D,YAAY,WAAmB,EAAE,cAAuB;QACpD,IAAI,QAAQ,GAAG,WAAW,CAAC;QAC3B,IAAI,cAAc,EAAE;YAChB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC,iBAAiB,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAG,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC;YACjF,IAAI,CAAC,cAAc,GAAG,IAAI,CAAA;SAC7B;aAAM;YACH,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;YACjB,IAAI,CAAC,cAAc,GAAG,KAAK,CAAA;SAC9B;IACL,CAAC;IAED,eAAe;IACR,KAAK,CAAC,cAAc,CAAC,OAAe;QACvC,IAAI,IAAI,CAAC,cAAc,EAAE;YACrB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;SACvC;IACL,CAAC;CACJ;AAED,kBAAe,MAAM,CAAC"}
|
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,12 +1,13 @@
|
|
|
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
|
+
"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
|
+
};
|
|
13
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG;IAC1B,eAAe,EAAE,qBAAqB;IACtC,YAAY,EAAE,+BAA+B;IAC7C,sBAAsB,EAAE,oCAAoC;IAC5D,oBAAoB,EAAE,gGAAgG;IACtH,oBAAoB,EAAE,gGAAgG;IACtH,uBAAuB,EAAE,qFAAqF;IAC9G,kBAAkB,EAAE,8DAA8D;CACrF,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function clonePingResponse(obj) {
|
|
4
|
+
var _a;
|
|
5
|
+
return {
|
|
6
|
+
host: obj.host,
|
|
7
|
+
numericHost: obj.numericHost,
|
|
8
|
+
alive: obj.alive,
|
|
9
|
+
output: obj.output,
|
|
10
|
+
time: obj.time,
|
|
11
|
+
times: ((_a = obj.times) === null || _a === void 0 ? void 0 : _a.length) ? [...obj.times] : [],
|
|
12
|
+
min: obj.min,
|
|
13
|
+
max: obj.max,
|
|
14
|
+
avg: obj.avg,
|
|
15
|
+
bufferSize: obj.bufferSize,
|
|
16
|
+
stddev: obj.stddev,
|
|
17
|
+
packetLoss: obj.packetLoss,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
exports.default = clonePingResponse;
|
|
21
|
+
//# sourceMappingURL=clonePingResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clonePingResponse.js","sourceRoot":"","sources":["../../../src/parser/clonePingResponse.ts"],"names":[],"mappings":";;AAEA,SAAS,iBAAiB,CAAC,GAAiB;;IAC1C,OAAO;QACL,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,KAAK,EAAE,CAAA,MAAA,GAAG,CAAC,KAAK,0CAAE,MAAM,EAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;QAC9C,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,UAAU,EAAE,GAAG,CAAC,UAAU;KAC3B,CAAC;AACJ,CAAC;AAED,kBAAe,iBAAiB,CAAC"}
|
|
@@ -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,31 @@
|
|
|
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;
|
|
31
|
+
//# sourceMappingURL=linux.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linux.js","sourceRoot":"","sources":["../../../src/parser/linux.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AAGxB,kFAAkF;AAClF,MAAM,KAAM,SAAQ,aAAG;IACnB,YAAY,QAAsB,EAAE,OAA6B;QAC7D,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC7B,CAAC;IAED,aAAa,CAAC,IAAY;QACtB,4BAA4B;QAC5B,IAAI,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,cAAc,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;QAEnD,IAAI,cAAc,EAAE;YAChB,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAC/B,IAAI,CAAC,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;SACtD;aAAM;YACH,+CAA+C;YAC/C,IAAI,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;YACvE,IAAG,cAAc,EAAC;gBACd,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,cAAc,CAAC,KAAK,EAAE,CAAC;gBAC5C,IAAI,CAAC,QAAQ,CAAC,WAAW,GAAG,cAAc,CAAC,GAAG,EAAE,CAAC;aACpD;SACJ;IACL,CAAC;CACJ;AAED,kBAAe,KAAK,CAAC"}
|
package/dist/src/parser/mac.d.ts
CHANGED
|
@@ -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;
|
package/dist/src/parser/mac.js
CHANGED
|
@@ -1,46 +1,47 @@
|
|
|
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;
|
|
47
|
+
//# sourceMappingURL=mac.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mac.js","sourceRoot":"","sources":["../../../src/parser/mac.ts"],"names":[],"mappings":";;AAGA,MAAM,GAAG;IAGL,YAAY,QAAsB,EAAE,OAA6B;QAC7D,IAAI,CAAC,MAAM,GAAG,OAAO,CAAA;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,EAAE,CAAA;IAC5B,CAAC;IAED,aAAa,CAAC,IAAY;QACtB,4BAA4B;QAC5B,IAAI,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE7B,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,CAAC,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACvD,CAAC;IAED,WAAW,CAAC,IAAY;QACpB,mDAAmD;QACnD,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QAC5C,IAAI,KAAK,IAAI,CAAC,EAAE;YACZ,IAAI,MAAM,GAAG,iBAAiB,CAAC;YAC/B,IAAI,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC9B,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;SACjE;IACL,CAAC;IAED,aAAa,CAAC,IAAY;QACtB,IAAI,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QAC1C,IAAI,UAAU,EAAE;YACZ,IAAI,CAAC,QAAQ,CAAC,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;SAC5C;QAED,iDAAiD;QACjD,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QAChD,IAAI,KAAK,IAAI,CAAC,EAAE;YACZ,MAAM,MAAM,GAAG,YAAY,CAAC;YAC5B,iCAAiC;YACjC,IAAI,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3B,IAAI,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3B,IAAI,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3B,IAAI,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAE3B,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAClD,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAClD,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAClD,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;SACxD;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;CACJ;AAED,kBAAe,GAAG,CAAC"}
|