A cli tool to quickly create and manage nginx server blocks.
https://up.js.org
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
454 B
25 lines
454 B
7 years ago
|
// Parses a string, and returns true if it is an IP Address.
|
||
|
|
||
|
function isIP(str) {
|
||
|
var segments = str
|
||
7 years ago
|
.split(".")
|
||
|
.map(Number);
|
||
7 years ago
|
if (!segments.length === 4) {
|
||
|
return false;
|
||
7 years ago
|
}
|
||
|
for(var i = 0; i < segments.length; i++) {
|
||
|
var segment = segments[i];
|
||
|
if (Number.isNaN(segment)) {
|
||
|
return false;
|
||
|
}
|
||
|
if (segment < 1 || segment > 255) {
|
||
|
return false;
|
||
|
}
|
||
7 years ago
|
}
|
||
|
if (segments[3] > 254) {
|
||
7 years ago
|
return false;
|
||
7 years ago
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
module.exports = isIP;
|