How to use the range_check.ver 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 keverw / node_CloudFlare / node_CloudFlare.js View on Github external
function check(req)
	{
		var ip_address = (req.connection.remoteAddress ? req.connection.remoteAddress : req.remoteAddress);
		if (typeof req.headers['cf-connecting-ip'] === 'undefined')
		{
			return false;
		}
		else
		{
			var range_check = require('range_check');
			if (range_check.vaild_ip(ip_address))
			{
				var ip_ver = range_check.ver(ip_address);
				if (ip_ver === 4)
				{
					return range_check.in_range(ip_address, ranges.v4);
				}
				else if (ip_ver === 6)
				{
					return range_check.in_range(ip_address, ranges.v6);
				}
				else
				{
					return false;
				}
			}
			else
			{
				return false;
github Mewte / cloudflare-express / index.js View on Github external
return function(req,res,next){
			var remoteIP = {
				ip: req.ip.replace("::ffff:",""), //app.set trust proxy could potentially modify this and cause issues
				v: "ip"+range_check.ver(req.ip.replace("::ffff:",""))
			};
			req.cf_ip = remoteIP.ip;//override this if cloudflare present
			if (req.headers['cf-connecting-ip'] == undefined){
				return next(); //no cloudflare IP, continue on like this never happened. Shhhh!
			}
			if (range_check.in_range(remoteIP.ip, ipRanges[remoteIP.v])){
				req.cf_ip = req.headers['cf-connecting-ip'];
			}
			next();
		};
	};

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 3 years ago

Package Health Score

50 / 100
Full package analysis