JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 89546
  • Score
    100M100P100Q156492F
  • License BSD

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

Package Exports

  • range_check

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (range_check) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Range Check v1.3.0

npm version   Build Status

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

This started out as range_check but it does much more than just checking ranges but since it's already got a large amount of downloads (37,115 downloads in the last month as of this writing) I'll keep the name the same even though I kinda want to change it to something better.

Install

To set up Range Check on your Node.js server use npm.

npm install range_check

IP Functions

Check if IP is valid

var rangeCheck = require('range_check');
console.log(rangeCheck.isIP('10.0.1.5')); //returns true or false

Check IP version

var rangeCheck = require('range_check');
console.log(rangeCheck.ver('10.0.1.5')); //returns 4
console.log(rangeCheck.ver('2001:4860:8006::62')); //returns 6
console.log(rangeCheck.ver('foo')); //returns 0 as invalid IP address

Range Functions

Check if range is valid

You can use isRange if you want to validate an entire range.

var rangeCheck = require('range_check');

console.log(rangeCheck.isRange('2001:db8::/32')); //true
console.log(rangeCheck.isRange('10.0.0.0/8')); // true
console.log(rangeCheck.isRange('qwerty')); // false

Check if IP is within range

var rangeCheck = require('range_check');
console.log(rangeCheck.inRange('10.0.1.5', '10.0.0.0/8')); //returns true

console.log(rangeCheck.inRange('192.0.1.5', '10.0.0.0/8')); //returns false

console.log(rangeCheck.inRange('2001:db8:1234::1', '2001:db8::/32')); //returns true

You can also give a list of ranges

var rangeCheck = require('range_check');
console.log(rangeCheck.inRange('192.168.1.1', ['10.0.0.0/8', '192.0.0.0/8'])); //returns true

Dependencies