Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

readme.md 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # Range Check v1.4.0
  2. [![npm version](https://badge.fury.io/js/range_check.svg)](https://badge.fury.io/js/range_check)   [![Build Status](https://travis-ci.org/keverw/range_check.svg?branch=master)](https://travis-ci.org/keverw/range_check)
  3. This is a simple module to validate IP address, check IP address version, check if IP is within a range.
  4. 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.
  5. <!-- START doctoc generated TOC please keep comment here to allow auto update -->
  6. <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
  7. - [Install](#install)
  8. - [IP Functions](#ip-functions)
  9. - [Check if IP is valid](#check-if-ip-is-valid)
  10. - [Check IP version](#check-ip-version)
  11. - [Ver](#ver)
  12. - [isV4](#isv4)
  13. - [isV6](#isv6)
  14. - [storeIP](#storeip)
  15. - [searchIP](#searchip)
  16. - [displayIP](#displayip)
  17. - [Range Functions](#range-functions)
  18. - [Check if range is valid](#check-if-range-is-valid)
  19. - [Check if IP is within range](#check-if-ip-is-within-range)
  20. - [Dependencies](#dependencies)
  21. <!-- END doctoc generated TOC please keep comment here to allow auto update -->
  22. ## Install
  23. To set up Range Check on your Node.js server use npm.
  24. `npm install range_check`
  25. ## IP Functions
  26. ### Check if IP is valid
  27. ```js
  28. var rangeCheck = require('range_check');
  29. console.log(rangeCheck.isIP('10.0.1.5')); //returns true or false
  30. ```
  31. ### Check IP version
  32. #### Ver
  33. ```
  34. var rangeCheck = require('range_check');
  35. console.log(rangeCheck.ver('10.0.1.5')); //returns 4
  36. console.log(rangeCheck.ver('2001:4860:8006::62')); //returns 6
  37. console.log(rangeCheck.ver('foo')); //returns 0 as invalid IP address
  38. ```
  39. #### isV4
  40. ```js
  41. var rangeCheck = require('range_check');
  42. console.log(rangeCheck.isV4('10.0.1.5')); //true
  43. console.log(rangeCheck.isV4('foo')); //false
  44. console.log(rangeCheck.isV4('123::123')); //false
  45. ```
  46. #### isV6
  47. ```js
  48. var rangeCheck = require('range_check');
  49. console.log(rangeCheck.isV6('123::123')); //true
  50. console.log(rangeCheck.isV6('foo')); //false
  51. console.log(rangeCheck.isV6('10.0.1.5')); //false
  52. ```
  53. ### storeIP
  54. This function is useful to get a consistent IP address such for storing it in a database or when searching in a database after being stored using this. So if a V6 address was sent compacted or not, or if you searched by either version this function would make sure you get a consistent IP address for both versions. Also the possibly of saving a few bytes.
  55. If an V6 addressed mapped as v4 is given it will convert it to V4, If any other V6 address is given it is __abbreviated__ and plain V4 addresses are left alone. Returns null if a invalid IP
  56. ```js
  57. var rangeCheck = require('../range_check.js');
  58. console.log(rangeCheck.storeIP('foo')); //null
  59. console.log(rangeCheck.storeIP('::ffff:127.0.0.1')); //127.0.0.1
  60. console.log(rangeCheck.storeIP('2001:0000:0111:0000:0011:0000:0001:0000')); //2001:0:111:0:11:0:1:0
  61. console.log(rangeCheck.storeIP('2001:0001:0000:0001:0000:0000:0000:0000')); //2001:1:0:1::
  62. console.log(rangeCheck.storeIP('0000:0000:0000:0000:0000:0000:0000:0000')); //::
  63. console.log(rangeCheck.storeIP('0000:0000:0000:0000:0000:0000:0000:0001')); //::1
  64. console.log(rangeCheck.storeIP('2041:0000:140F:0000:0000:0000:875B:131B')); //2041:0:140F::875B:131B
  65. console.log(rangeCheck.storeIP('2001:0001:0002:0003:0004:0005:0006:0007')); //2001:1:2:3:4:5:6:7
  66. console.log(rangeCheck.storeIP('127.0.0.1')); //127.0.0.1
  67. ```
  68. ### searchIP
  69. Same function as `storeIP`, just a clearer name when you are using it for search instead
  70. ### displayIP
  71. This function is useful for displaying IP addresses, such as after grabbing it back from the database when using `storeIP`
  72. If an V6 addressed mapped as v4 is given it will convert it to V4, If any other V6 address is given it is __normalized__ into the longer version and plain V4 addresses are left alone. Returns a empty string if a invalid IP
  73. ```js
  74. var rangeCheck = require('../range_check.js');
  75. console.log(rangeCheck.displayIP(null)); // ''
  76. console.log(rangeCheck.displayIP('::ffff:127.0.0.1')); //'127.0.0.1'
  77. console.log(rangeCheck.displayIP('2001:0:111:0:11:0:1:0')); //'2001:0000:0111:0000:0011:0000:0001:0000'
  78. console.log(rangeCheck.displayIP('2001:1:0:1::')); //'2001:0001:0000:0001:0000:0000:0000:0000'
  79. console.log(rangeCheck.displayIP('::')); //'0000:0000:0000:0000:0000:0000:0000:0000'
  80. console.log(rangeCheck.displayIP('::1')); //'0000:0000:0000:0000:0000:0000:0000:0001'
  81. console.log(rangeCheck.displayIP('2041:0:140F::875B:131B')); //'2041:0000:140F:0000:0000:0000:875B:131B'
  82. console.log(rangeCheck.displayIP('2001:1:2:3:4:5:6:7')); //'2001:0001:0002:0003:0004:0005:0006:0007'
  83. console.log(rangeCheck.displayIP('127.0.0.1')); //'127.0.0.1'
  84. ```
  85. ## Range Functions
  86. ### Check if range is valid
  87. You can use isRange if you want to validate an entire range.
  88. ```js
  89. var rangeCheck = require('range_check');
  90. console.log(rangeCheck.isRange('2001:db8::/32')); //true
  91. console.log(rangeCheck.isRange('10.0.0.0/8')); // true
  92. console.log(rangeCheck.isRange('qwerty')); // false
  93. ```
  94. ### Check if IP is within range
  95. ```js
  96. var rangeCheck = require('range_check');
  97. console.log(rangeCheck.inRange('10.0.1.5', '10.0.0.0/8')); //returns true
  98. console.log(rangeCheck.inRange('192.0.1.5', '10.0.0.0/8')); //returns false
  99. console.log(rangeCheck.inRange('2001:db8:1234::1', '2001:db8::/32')); //returns true
  100. ```
  101. You can also give a list of ranges
  102. ```js
  103. var rangeCheck = require('range_check');
  104. console.log(rangeCheck.inRange('192.168.1.1', ['10.0.0.0/8', '192.0.0.0/8'])); //returns true
  105. ```
  106. ## Dependencies
  107. * ipaddr.js - [https://github.com/whitequark/ipaddr.js](https://github.com/whitequark/ipaddr.js)
  108. * ip6 - [https://github.com/elgs/ip6](https://github.com/elgs/ip6)