How to use the range_check.in_range 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 pcimino / nodejs-restify-mongodb / config / middlewares / authorization.js View on Github external
User.findById(id, function (err, user) {
      if (!err) {
         if (user) {
           if (user.allowAccess('Admin')) {
             // check for IP Range
             if (!range_check.in_range(req.connection.remoteAddress, config.adminIPRange)) {
       //        console.log("IP Address " + req.connection.remoteAddress + " is not within the allowed range(s).")
               return next(new restify.NotAuthorizedError("Access restricted."));
             }
           }
            return next({});
         } else {
            return next(new restify.NotAuthorizedError("Access restricted."));
         }
      } else {
         return next(new restify.NotAuthorizedError("Access restricted."));
      }
   });
  } else {
github tjfontaine / dnsbalance / lib / serverrequest.js View on Github external
this.zone = this.zones.have(this.question.name);

  if (!this.zone) {
    winston.debug('Not our zone', [this.question.name]);

    address = this.req._socket._remote.address;

    for (aclname in this.cfg.acl) {
      acl = this.cfg.acl[aclname];

      if (!(acl.ip instanceof Array))
        acl.ip = [acl.ip];

      for (i in acl.ip) {
        ip = acl.ip[i];
        if (ip == address || check.in_range(address, ip)) {
          found = true;
          break;
        }
      }

      if (found)
        break;
    }

    winston.debug('Recursion', [found, acl]);
    if (found && acl.recursion) {
      next = this.recurse;
    } else {
      this.forbidden();
      return;
    }
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();
		};
	};
github keverw / node_CloudFlare / node_CloudFlare.js View on Github external
{
			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 hayes / unpm / lib / cidr.js View on Github external
function check(respond, route, unpm, done) {
    var ip = respond.req.connection.remoteAddress
    var allowed =  cidrCheck.in_range(ip, unpm.config.cidr)

    if(allowed) {
      return done()
    }

    unpm.log.info({ip: ip, message: 'IP out of CIDR range'})

    respond.res.writeHead(403, {
      'Content-Type': 'application/json'
    })

    respond.res.end(JSON.stringify({
      error: 'forbidden',
      reason: 'invalid ip'
    }))
  }
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;
			}
		}
	}

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