Browse Source

support net mask

develop
ray-1337 3 years ago
parent
commit
bbc49c6dee
  1. 5
      src/Util.js

5
src/Util.js

@ -93,8 +93,9 @@ module.exports.checkAppropriateIP = function(address) {
throw new Error("The address must be type of number."); throw new Error("The address must be type of number.");
}; };
// https://stackoverflow.com/a/5284410 // https://blog.markhatton.co.uk/2011/03/15/regular-expressions-for-ip-addresses-cidr-ranges-and-hostnames/
let regex = new RegExp(/\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}\b/gi); // also support subnet/net mask
let regex = new RegExp(/^(([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])(\/(3[0-2]|[1-2][0-9]|[0-9]))?$/gi);
if (!address.match(regex)) { if (!address.match(regex)) {
throw new Error(`The IP address is not matched with ${regex.toString()} regular expressions.`); throw new Error(`The IP address is not matched with ${regex.toString()} regular expressions.`);
}; };

Loading…
Cancel
Save