From f30fca6e2c9dacb2e13262b06928a16b75b8dd00 Mon Sep 17 00:00:00 2001 From: ray-1337 <33544674+ray-1337@users.noreply.github.com> Date: Mon, 11 Apr 2022 21:12:44 +0200 Subject: [PATCH] added check ip address method --- src/Util.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Util.js b/src/Util.js index 44dbd41..e683286 100644 --- a/src/Util.js +++ b/src/Util.js @@ -88,6 +88,20 @@ module.exports.checkAppropriatePort = function(port) { return true; }; +module.exports.checkAppropriateIP = function(address) { + if (typeof address !== "string") { + throw new Error("The address must be type of number."); + }; + + // https://stackoverflow.com/a/5284410 + let regex = new RegExp(/\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}\b/gi); + if (!address.match(regex)) { + throw new Error(`The IP address is not matched with ${regex.toString()} regular expressions.`); + }; + + return true; +}; + // soon to be continued // module.exports.checkPlatformVersion = function () { // let distroInfo = this.getDistroInfo();