How to use the range_check.valid_ip function in range_check

To help you get started, we’ve selected a few range_check examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MarcDiethelm / xtc / lib / validator.js View on Github external
validator.ipRanges = function(ipRanges) {
	var rangeCheck = require('range_check')
	   ,i , current
	   ,invalidIps = []
	;

	for (i = 0; i < ipRanges.length; i++) {
		current = ipRanges[i].split('/');
		if ( !rangeCheck.valid_ip(current[0]) ) {
			invalidIps.push('"'+current[0]+'"');
		}

		if ( current[1] && (current[1] < 17 || current[1] > 32) ) {
			invalidIps.push('"/'+ current[1]+'"');
		}
	}

	return invalidIps.length ? new Error('Invalid IPs/ranges: '+ invalidIps.join(', ')) : true;
};

range_check

This is a simple module to validate IP address, check ip address version, check if ip is within a range.

BSD-2-Clause
Latest version published 5 months ago

Package Health Score

64 / 100
Full package analysis