Update, insert new ping method
Took 29 minutes
This commit is contained in:
parent
ecb804fe4c
commit
cf29acee58
27
index.js
27
index.js
@ -3,6 +3,7 @@ const pug = require('pug');
|
||||
const fs = require("fs");
|
||||
const readline = require("readline");
|
||||
const ping = require('ping');
|
||||
const ldevices = require("local-devices");
|
||||
|
||||
const app = Express();
|
||||
const port = 3333;
|
||||
@ -36,7 +37,7 @@ app.get( '/api/getDeviceStatus/:ipAddress', async ( req, res ) => {
|
||||
timeout: 5,
|
||||
extra: ['-i', '1'],
|
||||
});
|
||||
console.log(ping_response);
|
||||
|
||||
let response = apiResponse;
|
||||
response.status = 200;
|
||||
res.status(200);
|
||||
@ -44,11 +45,25 @@ app.get( '/api/getDeviceStatus/:ipAddress', async ( req, res ) => {
|
||||
|
||||
if( ping_response.alive )
|
||||
{
|
||||
console.log( "Device is online(" + ping_response.time + " ms)!" );
|
||||
data = { online: true, host: ping_response.host, time: ping_response.time, avg: ping_response.avg }
|
||||
}
|
||||
else
|
||||
{
|
||||
data = { online: false, host: ping_response.host, time: ping_response.time, avg: ping_response.avg }
|
||||
console.log( "Device might be offline... trying another method...");
|
||||
// try with another method
|
||||
// Find a single device by ip address.
|
||||
let device = await ldevices(req.params.ipAddress);
|
||||
if( !device )
|
||||
{
|
||||
console.log( "Device is offline!" );
|
||||
data = { online: false, host: ping_response.host, time: ping_response.time, avg: ping_response.avg }
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log( "Device is online(unknown ms)!" );
|
||||
data = { online: true, host: device.name, time: "unknown", avg: "unknown" }
|
||||
}
|
||||
}
|
||||
|
||||
response.data = data;
|
||||
@ -74,6 +89,14 @@ app.get( '/api/getDevices', async ( req, res ) => {
|
||||
thisData.macAddress = line.substr( 0, line.indexOf( ' ' ) );
|
||||
thisData.ipAddress = line.substr( thisData.macAddress.length +1, line.substr( thisData.macAddress.length+1 ).indexOf( ' ') );
|
||||
thisData.hostname = line.substr( thisData.macAddress.length + thisData.ipAddress.length +2, line.length-1 );
|
||||
/* if( thisData.hostname == 'unknown' || thisData.hostname.startsWith( '*' ) || thisData.hostname == '' )
|
||||
{
|
||||
let device = await ldevices(req.params.ipAddress);
|
||||
if( !device )
|
||||
{
|
||||
thisData.hostname = device.name;
|
||||
}
|
||||
}*/
|
||||
//console.log( nline );
|
||||
data.push( thisData );
|
||||
}
|
||||
|
119
node_modules/.package-lock.json
generated
vendored
119
node_modules/.package-lock.json
generated
vendored
@ -58,6 +58,11 @@
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/any-promise": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz",
|
||||
"integrity": "sha1-q8av7tzqUugJzcA3au0845Y10X8="
|
||||
},
|
||||
"node_modules/array-flatten": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
|
||||
@ -132,6 +137,11 @@
|
||||
"is-regex": "^1.0.3"
|
||||
}
|
||||
},
|
||||
"node_modules/cidr-regex": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/cidr-regex/-/cidr-regex-1.0.7.tgz",
|
||||
"integrity": "sha1-N4L++3nIHX0zBpDN4xoP40Rf05s="
|
||||
},
|
||||
"node_modules/constantinople": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/constantinople/-/constantinople-4.0.1.tgz",
|
||||
@ -316,6 +326,16 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/get-ip-range": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/get-ip-range/-/get-ip-range-2.1.1.tgz",
|
||||
"integrity": "sha512-n401kTpf57VhbW2UvInXxhw1DgTJSsZf24gpNhJrFU8Cv+Jk/sQ+qukP2x0EF4MUEjDWlDLeIhIY/f80IV0kqg==",
|
||||
"dependencies": {
|
||||
"cidr-regex": "^1.0.7",
|
||||
"ip": "^1.1.5",
|
||||
"ip-address": "^6.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/has": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
|
||||
@ -383,6 +403,28 @@
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
|
||||
},
|
||||
"node_modules/ip": {
|
||||
"version": "1.1.5",
|
||||
"resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz",
|
||||
"integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo="
|
||||
},
|
||||
"node_modules/ip-address": {
|
||||
"version": "6.4.0",
|
||||
"resolved": "https://registry.npmjs.org/ip-address/-/ip-address-6.4.0.tgz",
|
||||
"integrity": "sha512-c5uxc2WUTuRBVHT/6r4m7HIr/DfV0bF6DvLH3iZGSK8wp8iMwwZSgIq2do0asFf8q9ECug0SE+6+1ACMe4sorA==",
|
||||
"dependencies": {
|
||||
"jsbn": "1.1.0",
|
||||
"lodash.find": "4.6.0",
|
||||
"lodash.max": "4.0.1",
|
||||
"lodash.merge": "4.6.2",
|
||||
"lodash.padstart": "4.6.1",
|
||||
"lodash.repeat": "4.1.0",
|
||||
"sprintf-js": "1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/ipaddr.js": {
|
||||
"version": "1.9.1",
|
||||
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
||||
@ -436,6 +478,11 @@
|
||||
"resolved": "https://registry.npmjs.org/js-stringify/-/js-stringify-1.0.2.tgz",
|
||||
"integrity": "sha1-Fzb939lyTyijaCrcYjCufk6Weds="
|
||||
},
|
||||
"node_modules/jsbn": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz",
|
||||
"integrity": "sha1-sBMHyym2GKHtJux56RH4A8TaAEA="
|
||||
},
|
||||
"node_modules/jstransformer": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jstransformer/-/jstransformer-1.0.0.tgz",
|
||||
@ -445,6 +492,44 @@
|
||||
"promise": "^7.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/local-devices": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/local-devices/-/local-devices-3.1.0.tgz",
|
||||
"integrity": "sha512-F0AFnjc5PJFNp4aVub6pV1/VqlXUQc/RBpBA2wyBLfDuXls3Ap25dOv9/7pWK2GDdcFVVi7IgBrMJXCH3txq0Q==",
|
||||
"dependencies": {
|
||||
"get-ip-range": "^2.1.0",
|
||||
"ip": "^1.1.5",
|
||||
"mz": "^2.7.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.17"
|
||||
}
|
||||
},
|
||||
"node_modules/lodash.find": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.find/-/lodash.find-4.6.0.tgz",
|
||||
"integrity": "sha1-ywcE1Hq3F4n/oN6Ll92Sb7iLE7E="
|
||||
},
|
||||
"node_modules/lodash.max": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash.max/-/lodash.max-4.0.1.tgz",
|
||||
"integrity": "sha1-hzVWbGGLNan3YFILSHrnllivE2o="
|
||||
},
|
||||
"node_modules/lodash.merge": {
|
||||
"version": "4.6.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
|
||||
"integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ=="
|
||||
},
|
||||
"node_modules/lodash.padstart": {
|
||||
"version": "4.6.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash.padstart/-/lodash.padstart-4.6.1.tgz",
|
||||
"integrity": "sha1-0uPuv/DZ05rVD1y9G1KnvOa7YRs="
|
||||
},
|
||||
"node_modules/lodash.repeat": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.repeat/-/lodash.repeat-4.1.0.tgz",
|
||||
"integrity": "sha1-/H3oEx2MisB+S0n3T/6CnR8r7EQ="
|
||||
},
|
||||
"node_modules/media-typer": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
||||
@ -501,6 +586,16 @@
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"node_modules/mz": {
|
||||
"version": "2.7.0",
|
||||
"resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz",
|
||||
"integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==",
|
||||
"dependencies": {
|
||||
"any-promise": "^1.0.0",
|
||||
"object-assign": "^4.0.1",
|
||||
"thenify-all": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/negotiator": {
|
||||
"version": "0.6.2",
|
||||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
|
||||
@ -798,6 +893,11 @@
|
||||
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
|
||||
"integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
|
||||
},
|
||||
"node_modules/sprintf-js": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.2.tgz",
|
||||
"integrity": "sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug=="
|
||||
},
|
||||
"node_modules/statuses": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
|
||||
@ -806,6 +906,25 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/thenify": {
|
||||
"version": "3.3.1",
|
||||
"resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz",
|
||||
"integrity": "sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==",
|
||||
"dependencies": {
|
||||
"any-promise": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/thenify-all": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz",
|
||||
"integrity": "sha1-GhkY1ALY/D+Y+/I02wvMjMEOlyY=",
|
||||
"dependencies": {
|
||||
"thenify": ">= 3.1.0 < 4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/to-fast-properties": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
|
||||
|
4
node_modules/any-promise/.jshintrc
generated
vendored
Normal file
4
node_modules/any-promise/.jshintrc
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"node":true,
|
||||
"strict":true
|
||||
}
|
7
node_modules/any-promise/.npmignore
generated
vendored
Normal file
7
node_modules/any-promise/.npmignore
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
.git*
|
||||
test/
|
||||
test-browser/
|
||||
build/
|
||||
.travis.yml
|
||||
*.swp
|
||||
Makefile
|
19
node_modules/any-promise/LICENSE
generated
vendored
Normal file
19
node_modules/any-promise/LICENSE
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (C) 2014-2016 Kevin Beaty
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
161
node_modules/any-promise/README.md
generated
vendored
Normal file
161
node_modules/any-promise/README.md
generated
vendored
Normal file
@ -0,0 +1,161 @@
|
||||
## Any Promise
|
||||
|
||||
[](http://travis-ci.org/kevinbeaty/any-promise)
|
||||
|
||||
Let your library support any ES 2015 (ES6) compatible `Promise` and leave the choice to application authors. The application can *optionally* register its preferred `Promise` implementation and it will be exported when requiring `any-promise` from library code.
|
||||
|
||||
If no preference is registered, defaults to the global `Promise` for newer Node.js versions. The browser version defaults to the window `Promise`, so polyfill or register as necessary.
|
||||
|
||||
### Usage with global Promise:
|
||||
|
||||
Assuming the global `Promise` is the desired implementation:
|
||||
|
||||
```bash
|
||||
# Install any libraries depending on any-promise
|
||||
$ npm install mz
|
||||
```
|
||||
|
||||
The installed libraries will use global Promise by default.
|
||||
|
||||
```js
|
||||
// in library
|
||||
var Promise = require('any-promise') // the global Promise
|
||||
|
||||
function promiseReturningFunction(){
|
||||
return new Promise(function(resolve, reject){...})
|
||||
}
|
||||
```
|
||||
|
||||
### Usage with registration:
|
||||
|
||||
Assuming `bluebird` is the desired Promise implementation:
|
||||
|
||||
```bash
|
||||
# Install preferred promise library
|
||||
$ npm install bluebird
|
||||
# Install any-promise to allow registration
|
||||
$ npm install any-promise
|
||||
# Install any libraries you would like to use depending on any-promise
|
||||
$ npm install mz
|
||||
```
|
||||
|
||||
Register your preference in the application entry point before any other `require` of packages that load `any-promise`:
|
||||
|
||||
```javascript
|
||||
// top of application index.js or other entry point
|
||||
require('any-promise/register/bluebird')
|
||||
|
||||
// -or- Equivalent to above, but allows customization of Promise library
|
||||
require('any-promise/register')('bluebird', {Promise: require('bluebird')})
|
||||
```
|
||||
|
||||
Now that the implementation is registered, you can use any package depending on `any-promise`:
|
||||
|
||||
|
||||
```javascript
|
||||
var fsp = require('mz/fs') // mz/fs will use registered bluebird promises
|
||||
var Promise = require('any-promise') // the registered bluebird promise
|
||||
```
|
||||
|
||||
It is safe to call `register` multiple times, but it must always be with the same implementation.
|
||||
|
||||
Again, registration is *optional*. It should only be called by the application user if overriding the global `Promise` implementation is desired.
|
||||
|
||||
### Optional Application Registration
|
||||
|
||||
As an application author, you can *optionally* register a preferred `Promise` implementation on application startup (before any call to `require('any-promise')`:
|
||||
|
||||
You must register your preference before any call to `require('any-promise')` (by you or required packages), and only one implementation can be registered. Typically, this registration would occur at the top of the application entry point.
|
||||
|
||||
|
||||
#### Registration shortcuts
|
||||
|
||||
If you are using a known `Promise` implementation, you can register your preference with a shortcut:
|
||||
|
||||
|
||||
```js
|
||||
require('any-promise/register/bluebird')
|
||||
// -or-
|
||||
import 'any-promise/register/q';
|
||||
```
|
||||
|
||||
Shortcut registration is the preferred registration method as it works in the browser and Node.js. It is also convenient for using with `import` and many test runners, that offer a `--require` flag:
|
||||
|
||||
```
|
||||
$ ava --require=any-promise/register/bluebird test.js
|
||||
```
|
||||
|
||||
Current known implementations include `bluebird`, `q`, `when`, `rsvp`, `es6-promise`, `promise`, `native-promise-only`, `pinkie`, `vow` and `lie`. If you are not using a known implementation, you can use another registration method described below.
|
||||
|
||||
|
||||
#### Basic Registration
|
||||
|
||||
As an alternative to registration shortcuts, you can call the `register` function with the preferred `Promise` implementation. The benefit of this approach is that a `Promise` library can be required by name without being a known implementation. This approach does NOT work in the browser. To use `any-promise` in the browser use either registration shortcuts or specify the `Promise` constructor using advanced registration (see below).
|
||||
|
||||
```javascript
|
||||
require('any-promise/register')('when')
|
||||
// -or- require('any-promise/register')('any other ES6 compatible library (known or otherwise)')
|
||||
```
|
||||
|
||||
This registration method will try to detect the `Promise` constructor from requiring the specified implementation. If you would like to specify your own constructor, see advanced registration.
|
||||
|
||||
|
||||
#### Advanced Registration
|
||||
|
||||
To use the browser version, you should either install a polyfill or explicitly register the `Promise` constructor:
|
||||
|
||||
```javascript
|
||||
require('any-promise/register')('bluebird', {Promise: require('bluebird')})
|
||||
```
|
||||
|
||||
This could also be used for registering a custom `Promise` implementation or subclass.
|
||||
|
||||
Your preference will be registered globally, allowing a single registration even if multiple versions of `any-promise` are installed in the NPM dependency tree or are using multiple bundled JavaScript files in the browser. You can bypass this global registration in options:
|
||||
|
||||
|
||||
```javascript
|
||||
require('../register')('es6-promise', {Promise: require('es6-promise').Promise, global: false})
|
||||
```
|
||||
|
||||
### Library Usage
|
||||
|
||||
To use any `Promise` constructor, simply require it:
|
||||
|
||||
```javascript
|
||||
var Promise = require('any-promise');
|
||||
|
||||
return Promise
|
||||
.all([xf, f, init, coll])
|
||||
.then(fn);
|
||||
|
||||
|
||||
return new Promise(function(resolve, reject){
|
||||
try {
|
||||
resolve(item);
|
||||
} catch(e){
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
Except noted below, libraries using `any-promise` should only use [documented](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) functions as there is no guarantee which implementation will be chosen by the application author. Libraries should never call `register`, only the application user should call if desired.
|
||||
|
||||
|
||||
#### Advanced Library Usage
|
||||
|
||||
If your library needs to branch code based on the registered implementation, you can retrieve it using `var impl = require('any-promise/implementation')`, where `impl` will be the package name (`"bluebird"`, `"when"`, etc.) if registered, `"global.Promise"` if using the global version on Node.js, or `"window.Promise"` if using the browser version. You should always include a default case, as there is no guarantee what package may be registered.
|
||||
|
||||
|
||||
### Support for old Node.js versions
|
||||
|
||||
Node.js versions prior to `v0.12` may have contained buggy versions of the global `Promise`. For this reason, the global `Promise` is not loaded automatically for these old versions. If using `any-promise` in Node.js versions versions `<= v0.12`, the user should register a desired implementation.
|
||||
|
||||
If an implementation is not registered, `any-promise` will attempt to discover an installed `Promise` implementation. If no implementation can be found, an error will be thrown on `require('any-promise')`. While the auto-discovery usually avoids errors, it is non-deterministic. It is recommended that the user always register a preferred implementation for older Node.js versions.
|
||||
|
||||
This auto-discovery is only available for Node.jS versions prior to `v0.12`. Any newer versions will always default to the global `Promise` implementation.
|
||||
|
||||
### Related
|
||||
|
||||
- [any-observable](https://github.com/sindresorhus/any-observable) - `any-promise` for Observables.
|
||||
|
3
node_modules/any-promise/implementation.d.ts
generated
vendored
Normal file
3
node_modules/any-promise/implementation.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
declare var implementation: string;
|
||||
|
||||
export = implementation;
|
1
node_modules/any-promise/implementation.js
generated
vendored
Normal file
1
node_modules/any-promise/implementation.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('./register')().implementation
|
73
node_modules/any-promise/index.d.ts
generated
vendored
Normal file
73
node_modules/any-promise/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
declare class Promise <R> implements Promise.Thenable <R> {
|
||||
/**
|
||||
* If you call resolve in the body of the callback passed to the constructor,
|
||||
* your promise is fulfilled with result object passed to resolve.
|
||||
* If you call reject your promise is rejected with the object passed to resolve.
|
||||
* For consistency and debugging (eg stack traces), obj should be an instanceof Error.
|
||||
* Any errors thrown in the constructor callback will be implicitly passed to reject().
|
||||
*/
|
||||
constructor (callback: (resolve : (value?: R | Promise.Thenable<R>) => void, reject: (error?: any) => void) => void);
|
||||
|
||||
/**
|
||||
* onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects.
|
||||
* Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called.
|
||||
* Both callbacks have a single parameter , the fulfillment value or rejection reason.
|
||||
* "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve.
|
||||
* If an error is thrown in the callback, the returned promise rejects with that error.
|
||||
*
|
||||
* @param onFulfilled called when/if "promise" resolves
|
||||
* @param onRejected called when/if "promise" rejects
|
||||
*/
|
||||
then <U> (onFulfilled?: (value: R) => U | Promise.Thenable<U>, onRejected?: (error: any) => U | Promise.Thenable<U>): Promise<U>;
|
||||
then <U> (onFulfilled?: (value: R) => U | Promise.Thenable<U>, onRejected?: (error: any) => void): Promise<U>;
|
||||
|
||||
/**
|
||||
* Sugar for promise.then(undefined, onRejected)
|
||||
*
|
||||
* @param onRejected called when/if "promise" rejects
|
||||
*/
|
||||
catch <U> (onRejected?: (error: any) => U | Promise.Thenable<U>): Promise<U>;
|
||||
|
||||
/**
|
||||
* Make a new promise from the thenable.
|
||||
* A thenable is promise-like in as far as it has a "then" method.
|
||||
*/
|
||||
static resolve (): Promise<void>;
|
||||
static resolve <R> (value: R | Promise.Thenable<R>): Promise<R>;
|
||||
|
||||
/**
|
||||
* Make a promise that rejects to obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error
|
||||
*/
|
||||
static reject <R> (error: any): Promise<R>;
|
||||
|
||||
/**
|
||||
* Make a promise that fulfills when every item in the array fulfills, and rejects if (and when) any item rejects.
|
||||
* the array passed to all can be a mixture of promise-like objects and other objects.
|
||||
* The fulfillment value is an array (in order) of fulfillment values. The rejection value is the first rejection value.
|
||||
*/
|
||||
static all <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> (values: [T1 | Promise.Thenable<T1>, T2 | Promise.Thenable<T2>, T3 | Promise.Thenable<T3>, T4 | Promise.Thenable <T4>, T5 | Promise.Thenable<T5>, T6 | Promise.Thenable<T6>, T7 | Promise.Thenable<T7>, T8 | Promise.Thenable<T8>, T9 | Promise.Thenable<T9>, T10 | Promise.Thenable<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>;
|
||||
static all <T1, T2, T3, T4, T5, T6, T7, T8, T9> (values: [T1 | Promise.Thenable<T1>, T2 | Promise.Thenable<T2>, T3 | Promise.Thenable<T3>, T4 | Promise.Thenable <T4>, T5 | Promise.Thenable<T5>, T6 | Promise.Thenable<T6>, T7 | Promise.Thenable<T7>, T8 | Promise.Thenable<T8>, T9 | Promise.Thenable<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>;
|
||||
static all <T1, T2, T3, T4, T5, T6, T7, T8> (values: [T1 | Promise.Thenable<T1>, T2 | Promise.Thenable<T2>, T3 | Promise.Thenable<T3>, T4 | Promise.Thenable <T4>, T5 | Promise.Thenable<T5>, T6 | Promise.Thenable<T6>, T7 | Promise.Thenable<T7>, T8 | Promise.Thenable<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>;
|
||||
static all <T1, T2, T3, T4, T5, T6, T7> (values: [T1 | Promise.Thenable<T1>, T2 | Promise.Thenable<T2>, T3 | Promise.Thenable<T3>, T4 | Promise.Thenable <T4>, T5 | Promise.Thenable<T5>, T6 | Promise.Thenable<T6>, T7 | Promise.Thenable<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>;
|
||||
static all <T1, T2, T3, T4, T5, T6> (values: [T1 | Promise.Thenable<T1>, T2 | Promise.Thenable<T2>, T3 | Promise.Thenable<T3>, T4 | Promise.Thenable <T4>, T5 | Promise.Thenable<T5>, T6 | Promise.Thenable<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>;
|
||||
static all <T1, T2, T3, T4, T5> (values: [T1 | Promise.Thenable<T1>, T2 | Promise.Thenable<T2>, T3 | Promise.Thenable<T3>, T4 | Promise.Thenable <T4>, T5 | Promise.Thenable<T5>]): Promise<[T1, T2, T3, T4, T5]>;
|
||||
static all <T1, T2, T3, T4> (values: [T1 | Promise.Thenable<T1>, T2 | Promise.Thenable<T2>, T3 | Promise.Thenable<T3>, T4 | Promise.Thenable <T4>]): Promise<[T1, T2, T3, T4]>;
|
||||
static all <T1, T2, T3> (values: [T1 | Promise.Thenable<T1>, T2 | Promise.Thenable<T2>, T3 | Promise.Thenable<T3>]): Promise<[T1, T2, T3]>;
|
||||
static all <T1, T2> (values: [T1 | Promise.Thenable<T1>, T2 | Promise.Thenable<T2>]): Promise<[T1, T2]>;
|
||||
static all <T1> (values: [T1 | Promise.Thenable<T1>]): Promise<[T1]>;
|
||||
static all <TAll> (values: Array<TAll | Promise.Thenable<TAll>>): Promise<TAll[]>;
|
||||
|
||||
/**
|
||||
* Make a Promise that fulfills when any item fulfills, and rejects if any item rejects.
|
||||
*/
|
||||
static race <R> (promises: (R | Promise.Thenable<R>)[]): Promise<R>;
|
||||
}
|
||||
|
||||
declare namespace Promise {
|
||||
export interface Thenable <R> {
|
||||
then <U> (onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
|
||||
then <U> (onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => void): Thenable<U>;
|
||||
}
|
||||
}
|
||||
|
||||
export = Promise;
|
1
node_modules/any-promise/index.js
generated
vendored
Normal file
1
node_modules/any-promise/index.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('./register')().Promise
|
78
node_modules/any-promise/loader.js
generated
vendored
Normal file
78
node_modules/any-promise/loader.js
generated
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
"use strict"
|
||||
// global key for user preferred registration
|
||||
var REGISTRATION_KEY = '@@any-promise/REGISTRATION',
|
||||
// Prior registration (preferred or detected)
|
||||
registered = null
|
||||
|
||||
/**
|
||||
* Registers the given implementation. An implementation must
|
||||
* be registered prior to any call to `require("any-promise")`,
|
||||
* typically on application load.
|
||||
*
|
||||
* If called with no arguments, will return registration in
|
||||
* following priority:
|
||||
*
|
||||
* For Node.js:
|
||||
*
|
||||
* 1. Previous registration
|
||||
* 2. global.Promise if node.js version >= 0.12
|
||||
* 3. Auto detected promise based on first sucessful require of
|
||||
* known promise libraries. Note this is a last resort, as the
|
||||
* loaded library is non-deterministic. node.js >= 0.12 will
|
||||
* always use global.Promise over this priority list.
|
||||
* 4. Throws error.
|
||||
*
|
||||
* For Browser:
|
||||
*
|
||||
* 1. Previous registration
|
||||
* 2. window.Promise
|
||||
* 3. Throws error.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* Promise: Desired Promise constructor
|
||||
* global: Boolean - Should the registration be cached in a global variable to
|
||||
* allow cross dependency/bundle registration? (default true)
|
||||
*/
|
||||
module.exports = function(root, loadImplementation){
|
||||
return function register(implementation, opts){
|
||||
implementation = implementation || null
|
||||
opts = opts || {}
|
||||
// global registration unless explicitly {global: false} in options (default true)
|
||||
var registerGlobal = opts.global !== false;
|
||||
|
||||
// load any previous global registration
|
||||
if(registered === null && registerGlobal){
|
||||
registered = root[REGISTRATION_KEY] || null
|
||||
}
|
||||
|
||||
if(registered !== null
|
||||
&& implementation !== null
|
||||
&& registered.implementation !== implementation){
|
||||
// Throw error if attempting to redefine implementation
|
||||
throw new Error('any-promise already defined as "'+registered.implementation+
|
||||
'". You can only register an implementation before the first '+
|
||||
' call to require("any-promise") and an implementation cannot be changed')
|
||||
}
|
||||
|
||||
if(registered === null){
|
||||
// use provided implementation
|
||||
if(implementation !== null && typeof opts.Promise !== 'undefined'){
|
||||
registered = {
|
||||
Promise: opts.Promise,
|
||||
implementation: implementation
|
||||
}
|
||||
} else {
|
||||
// require implementation if implementation is specified but not provided
|
||||
registered = loadImplementation(implementation)
|
||||
}
|
||||
|
||||
if(registerGlobal){
|
||||
// register preference globally in case multiple installations
|
||||
root[REGISTRATION_KEY] = registered
|
||||
}
|
||||
}
|
||||
|
||||
return registered
|
||||
}
|
||||
}
|
6
node_modules/any-promise/optional.js
generated
vendored
Normal file
6
node_modules/any-promise/optional.js
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
try {
|
||||
module.exports = require('./register')().Promise || null
|
||||
} catch(e) {
|
||||
module.exports = null
|
||||
}
|
45
node_modules/any-promise/package.json
generated
vendored
Normal file
45
node_modules/any-promise/package.json
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "any-promise",
|
||||
"version": "1.3.0",
|
||||
"description": "Resolve any installed ES6 compatible promise",
|
||||
"main": "index.js",
|
||||
"typings": "index.d.ts",
|
||||
"browser": {
|
||||
"./register.js": "./register-shim.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "ava"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/kevinbeaty/any-promise"
|
||||
},
|
||||
"keywords": [
|
||||
"promise",
|
||||
"es6"
|
||||
],
|
||||
"author": "Kevin Beaty",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/kevinbeaty/any-promise/issues"
|
||||
},
|
||||
"homepage": "http://github.com/kevinbeaty/any-promise",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"ava": "^0.14.0",
|
||||
"bluebird": "^3.0.0",
|
||||
"es6-promise": "^3.0.0",
|
||||
"is-promise": "^2.0.0",
|
||||
"lie": "^3.0.0",
|
||||
"mocha": "^2.0.0",
|
||||
"native-promise-only": "^0.8.0",
|
||||
"phantomjs-prebuilt": "^2.0.0",
|
||||
"pinkie": "^2.0.0",
|
||||
"promise": "^7.0.0",
|
||||
"q": "^1.0.0",
|
||||
"rsvp": "^3.0.0",
|
||||
"vow": "^0.4.0",
|
||||
"when": "^3.0.0",
|
||||
"zuul": "^3.0.0"
|
||||
}
|
||||
}
|
18
node_modules/any-promise/register-shim.js
generated
vendored
Normal file
18
node_modules/any-promise/register-shim.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
module.exports = require('./loader')(window, loadImplementation)
|
||||
|
||||
/**
|
||||
* Browser specific loadImplementation. Always uses `window.Promise`
|
||||
*
|
||||
* To register a custom implementation, must register with `Promise` option.
|
||||
*/
|
||||
function loadImplementation(){
|
||||
if(typeof window.Promise === 'undefined'){
|
||||
throw new Error("any-promise browser requires a polyfill or explicit registration"+
|
||||
" e.g: require('any-promise/register/bluebird')")
|
||||
}
|
||||
return {
|
||||
Promise: window.Promise,
|
||||
implementation: 'window.Promise'
|
||||
}
|
||||
}
|
17
node_modules/any-promise/register.d.ts
generated
vendored
Normal file
17
node_modules/any-promise/register.d.ts
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
import Promise = require('./index');
|
||||
|
||||
declare function register (module?: string, options?: register.Options): register.Register;
|
||||
|
||||
declare namespace register {
|
||||
export interface Register {
|
||||
Promise: typeof Promise;
|
||||
implementation: string;
|
||||
}
|
||||
|
||||
export interface Options {
|
||||
Promise?: typeof Promise;
|
||||
global?: boolean
|
||||
}
|
||||
}
|
||||
|
||||
export = register;
|
94
node_modules/any-promise/register.js
generated
vendored
Normal file
94
node_modules/any-promise/register.js
generated
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
"use strict"
|
||||
module.exports = require('./loader')(global, loadImplementation);
|
||||
|
||||
/**
|
||||
* Node.js version of loadImplementation.
|
||||
*
|
||||
* Requires the given implementation and returns the registration
|
||||
* containing {Promise, implementation}
|
||||
*
|
||||
* If implementation is undefined or global.Promise, loads it
|
||||
* Otherwise uses require
|
||||
*/
|
||||
function loadImplementation(implementation){
|
||||
var impl = null
|
||||
|
||||
if(shouldPreferGlobalPromise(implementation)){
|
||||
// if no implementation or env specified use global.Promise
|
||||
impl = {
|
||||
Promise: global.Promise,
|
||||
implementation: 'global.Promise'
|
||||
}
|
||||
} else if(implementation){
|
||||
// if implementation specified, require it
|
||||
var lib = require(implementation)
|
||||
impl = {
|
||||
Promise: lib.Promise || lib,
|
||||
implementation: implementation
|
||||
}
|
||||
} else {
|
||||
// try to auto detect implementation. This is non-deterministic
|
||||
// and should prefer other branches, but this is our last chance
|
||||
// to load something without throwing error
|
||||
impl = tryAutoDetect()
|
||||
}
|
||||
|
||||
if(impl === null){
|
||||
throw new Error('Cannot find any-promise implementation nor'+
|
||||
' global.Promise. You must install polyfill or call'+
|
||||
' require("any-promise/register") with your preferred'+
|
||||
' implementation, e.g. require("any-promise/register/bluebird")'+
|
||||
' on application load prior to any require("any-promise").')
|
||||
}
|
||||
|
||||
return impl
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the global.Promise should be preferred if an implementation
|
||||
* has not been registered.
|
||||
*/
|
||||
function shouldPreferGlobalPromise(implementation){
|
||||
if(implementation){
|
||||
return implementation === 'global.Promise'
|
||||
} else if(typeof global.Promise !== 'undefined'){
|
||||
// Load global promise if implementation not specified
|
||||
// Versions < 0.11 did not have global Promise
|
||||
// Do not use for version < 0.12 as version 0.11 contained buggy versions
|
||||
var version = (/v(\d+)\.(\d+)\.(\d+)/).exec(process.version)
|
||||
return !(version && +version[1] == 0 && +version[2] < 12)
|
||||
}
|
||||
|
||||
// do not have global.Promise or another implementation was specified
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Look for common libs as last resort there is no guarantee that
|
||||
* this will return a desired implementation or even be deterministic.
|
||||
* The priority is also nearly arbitrary. We are only doing this
|
||||
* for older versions of Node.js <0.12 that do not have a reasonable
|
||||
* global.Promise implementation and we the user has not registered
|
||||
* the preference. This preserves the behavior of any-promise <= 0.1
|
||||
* and may be deprecated or removed in the future
|
||||
*/
|
||||
function tryAutoDetect(){
|
||||
var libs = [
|
||||
"es6-promise",
|
||||
"promise",
|
||||
"native-promise-only",
|
||||
"bluebird",
|
||||
"rsvp",
|
||||
"when",
|
||||
"q",
|
||||
"pinkie",
|
||||
"lie",
|
||||
"vow"]
|
||||
var i = 0, len = libs.length
|
||||
for(; i < len; i++){
|
||||
try {
|
||||
return loadImplementation(libs[i])
|
||||
} catch(e){}
|
||||
}
|
||||
return null
|
||||
}
|
1
node_modules/any-promise/register/bluebird.d.ts
generated
vendored
Normal file
1
node_modules/any-promise/register/bluebird.d.ts
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
export {}
|
2
node_modules/any-promise/register/bluebird.js
generated
vendored
Normal file
2
node_modules/any-promise/register/bluebird.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
require('../register')('bluebird', {Promise: require('bluebird')})
|
1
node_modules/any-promise/register/es6-promise.d.ts
generated
vendored
Normal file
1
node_modules/any-promise/register/es6-promise.d.ts
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
export {}
|
2
node_modules/any-promise/register/es6-promise.js
generated
vendored
Normal file
2
node_modules/any-promise/register/es6-promise.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
require('../register')('es6-promise', {Promise: require('es6-promise').Promise})
|
1
node_modules/any-promise/register/lie.d.ts
generated
vendored
Normal file
1
node_modules/any-promise/register/lie.d.ts
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
export {}
|
2
node_modules/any-promise/register/lie.js
generated
vendored
Normal file
2
node_modules/any-promise/register/lie.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
require('../register')('lie', {Promise: require('lie')})
|
1
node_modules/any-promise/register/native-promise-only.d.ts
generated
vendored
Normal file
1
node_modules/any-promise/register/native-promise-only.d.ts
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
export {}
|
2
node_modules/any-promise/register/native-promise-only.js
generated
vendored
Normal file
2
node_modules/any-promise/register/native-promise-only.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
require('../register')('native-promise-only', {Promise: require('native-promise-only')})
|
1
node_modules/any-promise/register/pinkie.d.ts
generated
vendored
Normal file
1
node_modules/any-promise/register/pinkie.d.ts
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
export {}
|
2
node_modules/any-promise/register/pinkie.js
generated
vendored
Normal file
2
node_modules/any-promise/register/pinkie.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
require('../register')('pinkie', {Promise: require('pinkie')})
|
1
node_modules/any-promise/register/promise.d.ts
generated
vendored
Normal file
1
node_modules/any-promise/register/promise.d.ts
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
export {}
|
2
node_modules/any-promise/register/promise.js
generated
vendored
Normal file
2
node_modules/any-promise/register/promise.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
require('../register')('promise', {Promise: require('promise')})
|
1
node_modules/any-promise/register/q.d.ts
generated
vendored
Normal file
1
node_modules/any-promise/register/q.d.ts
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
export {}
|
2
node_modules/any-promise/register/q.js
generated
vendored
Normal file
2
node_modules/any-promise/register/q.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
require('../register')('q', {Promise: require('q').Promise})
|
1
node_modules/any-promise/register/rsvp.d.ts
generated
vendored
Normal file
1
node_modules/any-promise/register/rsvp.d.ts
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
export {}
|
2
node_modules/any-promise/register/rsvp.js
generated
vendored
Normal file
2
node_modules/any-promise/register/rsvp.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
require('../register')('rsvp', {Promise: require('rsvp').Promise})
|
1
node_modules/any-promise/register/vow.d.ts
generated
vendored
Normal file
1
node_modules/any-promise/register/vow.d.ts
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
export {}
|
2
node_modules/any-promise/register/vow.js
generated
vendored
Normal file
2
node_modules/any-promise/register/vow.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
require('../register')('vow', {Promise: require('vow').Promise})
|
1
node_modules/any-promise/register/when.d.ts
generated
vendored
Normal file
1
node_modules/any-promise/register/when.d.ts
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
export {}
|
2
node_modules/any-promise/register/when.js
generated
vendored
Normal file
2
node_modules/any-promise/register/when.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
require('../register')('when', {Promise: require('when').Promise})
|
5
node_modules/cidr-regex/.eslintrc
generated
vendored
Normal file
5
node_modules/cidr-regex/.eslintrc
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends" : [
|
||||
"standard"
|
||||
]
|
||||
}
|
1
node_modules/cidr-regex/.npmignore
generated
vendored
Normal file
1
node_modules/cidr-regex/.npmignore
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
src/
|
21
node_modules/cidr-regex/.travis.yml
generated
vendored
Normal file
21
node_modules/cidr-regex/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
notifications:
|
||||
email: false
|
||||
node_js:
|
||||
- '4'
|
||||
before_install:
|
||||
- npm i -g npm@^3.0.0
|
||||
before_script:
|
||||
- npm prune
|
||||
script:
|
||||
- npm run test
|
||||
- npm run build
|
||||
after_success:
|
||||
- npm run semantic-release
|
||||
branches:
|
||||
except:
|
||||
- "/^v\\d+\\.\\d+\\.\\d+$/"
|
62
node_modules/cidr-regex/README.md
generated
vendored
Normal file
62
node_modules/cidr-regex/README.md
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
# cidr-regex
|
||||
|
||||
Regular expression for matching CIDR (Classless Inter-Domain Routing)
|
||||
|
||||
[](https://github.com/semantic-release/semantic-release)
|
||||
[](http://npm.im/cidr-regex)
|
||||
[](http://opensource.org/licenses/MIT)
|
||||
[](https://travis-ci.org/flipjs/cidr-regex)
|
||||
[](https://github.com/feross/standard)
|
||||
[](http://commitizen.github.io/cz-cli/)
|
||||
[](http://npm-stat.com/charts.html?package=cidr-regex&from=2016-03-24)
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
$ npm install --save cidr-regex
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import cidr from 'cidr-regex' // default regex is cidr v4
|
||||
import { cidrv4, cidrv6 } from 'cidr-regex'
|
||||
// OR
|
||||
var cidrv4 = require('cidr-regex').cidrv4
|
||||
var cidrv6 = require('cidr-regex').cidrv6
|
||||
|
||||
// is a CIDR v4
|
||||
cidr.test('18.101.25.153/24') // true
|
||||
|
||||
// is not a CIDR v4
|
||||
cidrv4.test('999.999.999.999/12') // false
|
||||
|
||||
// is a CIDR v6
|
||||
cidrv6.test('fe80:0000:0000:0000:0204:61ff:fe9d:f156') // true
|
||||
|
||||
// is not a CIDR v6
|
||||
cidrv6.test('fe80:0000:0000:0000:0204:61ff:fe9d:f156/a') // false
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### cidr
|
||||
|
||||
A regex for matching CIDR IPv4
|
||||
|
||||
### cidrv4
|
||||
|
||||
A regex for matching CIDR IPv4
|
||||
|
||||
### cidrv6
|
||||
|
||||
A regex for matching CIDR IPv6
|
||||
|
||||
## Other notes
|
||||
|
||||
This was inspired by npm package [ip-regex](https://www.npmjs.com/package/ip-regex). I've used the same samples on unit testing for IPv4 and modified for CIDR testing. Other IPv6 test cases were taken from [IPv6 Regex by Dartware, LLC](https://www.helpsystems.com/intermapper/ipv6-test-address-validation) (licensed under CC-BY-SA 3.0).
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Felipe Apostol](https://github.com/flipjs)
|
||||
|
14
node_modules/cidr-regex/example/example.js
generated
vendored
Normal file
14
node_modules/cidr-regex/example/example.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
var r = require('../lib')
|
||||
|
||||
var v4true = r.cidrv4.test('1.1.1.1/24')
|
||||
console.log('cidrv4 true is', v4true)
|
||||
|
||||
var v4false = r.cidrv4.test('1.1.1.256/24')
|
||||
console.log('cidrv4 false is', v4false)
|
||||
|
||||
var v6true = r.cidrv6.test('fe80:0000:0000:0000:0204:61ff:fe9d:f156')
|
||||
console.log('cidrv6 true is', v6true)
|
||||
|
||||
var v6false = r.cidrv6.test('fe80:0000:0000:0000:0204:61ff:fe9d:f156/sdfsdfs')
|
||||
console.log('cidrv6 false is', v6false)
|
||||
|
10
node_modules/cidr-regex/lib/index.js
generated
vendored
Normal file
10
node_modules/cidr-regex/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
var cidrv4 = exports.cidrv4 = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$/;
|
||||
|
||||
var cidrv6 = exports.cidrv6 = /^((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%\.+)?(\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8]))?$/;
|
||||
|
||||
exports.default = cidrv4;
|
61
node_modules/cidr-regex/package.json
generated
vendored
Normal file
61
node_modules/cidr-regex/package.json
generated
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
{
|
||||
"name": "cidr-regex",
|
||||
"version": "1.0.7",
|
||||
"description": "Regular expression for matching CIDR (Classless Inter-Domain Routing)",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"commit": "git-cz",
|
||||
"prebuild": "npm run lint && npm run clean",
|
||||
"build": "babel --presets es2015 -d lib/ src/",
|
||||
"clean": "rimraf lib && mkdir lib",
|
||||
"lint": "eslint src/ test/",
|
||||
"test": "ava --require babel-register",
|
||||
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/flipjs/cidr-regex.git"
|
||||
},
|
||||
"keywords": [
|
||||
"ip",
|
||||
"ip address",
|
||||
"cidr",
|
||||
"netblock",
|
||||
"regex"
|
||||
],
|
||||
"author": "Felipe Apostol <flipjs.io@gmail.com> (http://flipjs.io/)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/flipjs/cidr-regex/issues"
|
||||
},
|
||||
"homepage": "https://github.com/flipjs/cidr-regex#readme",
|
||||
"devDependencies": {
|
||||
"ava": "0.13.0",
|
||||
"babel-cli": "6.6.5",
|
||||
"babel-preset-es2015": "6.6.0",
|
||||
"babel-register": "6.7.2",
|
||||
"commitizen": "2.7.3",
|
||||
"cz-conventional-changelog": "1.1.5",
|
||||
"eslint": "2.4.0",
|
||||
"eslint-config-standard": "5.1.0",
|
||||
"eslint-plugin-babel": "3.1.0",
|
||||
"eslint-plugin-promise": "1.1.0",
|
||||
"eslint-plugin-standard": "1.3.2",
|
||||
"ghooks": "1.0.3",
|
||||
"rimraf": "2.5.2",
|
||||
"semantic-release": "4.3.5"
|
||||
},
|
||||
"babel": {
|
||||
"presets": [
|
||||
"es2015"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"commitizen": {
|
||||
"path": "node_modules/cz-conventional-changelog"
|
||||
},
|
||||
"ghooks": {
|
||||
"pre-commit": "npm run test && npm run build"
|
||||
}
|
||||
}
|
||||
}
|
579
node_modules/cidr-regex/test/index.test.js
generated
vendored
Normal file
579
node_modules/cidr-regex/test/index.test.js
generated
vendored
Normal file
@ -0,0 +1,579 @@
|
||||
'use strict'
|
||||
|
||||
import test from 'ava'
|
||||
import cidr, { cidrv4, cidrv6 } from '../src'
|
||||
|
||||
const v4 = [
|
||||
'0.0.0.0/16',
|
||||
'8.8.8.8/17',
|
||||
'127.0.0.1/18',
|
||||
'100.100.100.100/19',
|
||||
'192.168.0.1/20',
|
||||
'18.101.25.153/24',
|
||||
'123.23.34.2/25',
|
||||
'172.26.168.134/26',
|
||||
'212.58.241.131/27',
|
||||
'128.0.0.0/28',
|
||||
'23.71.254.72/29',
|
||||
'223.255.255.255/30',
|
||||
'192.0.2.235/31',
|
||||
'99.198.122.146/32',
|
||||
'46.51.197.88/8',
|
||||
'173.194.34.134/12'
|
||||
]
|
||||
|
||||
const v4not = [
|
||||
'.100.100.100.100/16',
|
||||
'100..100.100.100./24',
|
||||
'100.100.100.100./32',
|
||||
'999.999.999.999/12',
|
||||
'256.256.256.256/30',
|
||||
'256.100.100.100.100/26',
|
||||
'123.123.123/31',
|
||||
'http://123.123.123/28',
|
||||
'1000.2.3.4/14',
|
||||
'999.2.3.4/8'
|
||||
]
|
||||
|
||||
const v6 = [
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156/0',
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156/1',
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156/2',
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156/3',
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156/11',
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156/99',
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156/100',
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156/126',
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156/127',
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156/128',
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156',
|
||||
// test cases from Dartware IPv6 Regex
|
||||
'::1',
|
||||
'::',
|
||||
'0:0:0:0:0:0:0:1',
|
||||
'0:0:0:0:0:0:0:0',
|
||||
'2001:DB8:0:0:8:800:200C:417A',
|
||||
'FF01:0:0:0:0:0:0:101',
|
||||
'2001:DB8::8:800:200C:417A',
|
||||
'FF01::101',
|
||||
'fe80::217:f2ff:fe07:ed62',
|
||||
'2001:0000:1234:0000:0000:C1C0:ABCD:0876',
|
||||
'3ffe:0b00:0000:0000:0001:0000:0000:000a',
|
||||
'FF02:0000:0000:0000:0000:0000:0000:0001',
|
||||
'0000:0000:0000:0000:0000:0000:0000:0001',
|
||||
'0000:0000:0000:0000:0000:0000:0000:0000',
|
||||
'2001:0000:1234:0000:0000:C1C0:ABCD:0876',
|
||||
'2::10',
|
||||
'ff02::1',
|
||||
'fe80::',
|
||||
'2002::',
|
||||
'2001:db8::',
|
||||
'2001:0db8:1234::',
|
||||
'::ffff:0:0',
|
||||
'::1',
|
||||
'1:2:3:4:5:6:7:8',
|
||||
'1:2:3:4:5:6::8',
|
||||
'1:2:3:4:5::8',
|
||||
'1:2:3:4::8',
|
||||
'1:2:3::8',
|
||||
'1:2::8',
|
||||
'1::8',
|
||||
'1::2:3:4:5:6:7',
|
||||
'1::2:3:4:5:6',
|
||||
'1::2:3:4:5',
|
||||
'1::2:3:4',
|
||||
'1::2:3',
|
||||
'1::8',
|
||||
'::2:3:4:5:6:7:8',
|
||||
'::2:3:4:5:6:7',
|
||||
'::2:3:4:5:6',
|
||||
'::2:3:4:5',
|
||||
'::2:3:4',
|
||||
'::2:3',
|
||||
'::8',
|
||||
'1:2:3:4:5:6::',
|
||||
'1:2:3:4:5::',
|
||||
'1:2:3:4::',
|
||||
'1:2:3::',
|
||||
'1:2::',
|
||||
'1::',
|
||||
'1:2:3:4:5::7:8',
|
||||
'1:2:3:4::7:8',
|
||||
'1:2:3::7:8',
|
||||
'1:2::7:8',
|
||||
'1::7:8',
|
||||
'1:2:3:4:5:6:1.2.3.4',
|
||||
'1:2:3:4:5::1.2.3.4',
|
||||
'1:2:3:4::1.2.3.4',
|
||||
'1:2:3::1.2.3.4',
|
||||
'1:2::1.2.3.4',
|
||||
'1::1.2.3.4',
|
||||
'1:2:3:4::5:1.2.3.4',
|
||||
'1:2:3::5:1.2.3.4',
|
||||
'1:2::5:1.2.3.4',
|
||||
'1::5:1.2.3.4',
|
||||
'1::5:11.22.33.44',
|
||||
'fe80::217:f2ff:254.7.237.98',
|
||||
'::ffff:192.168.1.26',
|
||||
'::ffff:192.168.1.1',
|
||||
'0:0:0:0:0:0:13.1.68.3',
|
||||
'0:0:0:0:0:FFFF:129.144.52.38',
|
||||
'::13.1.68.3',
|
||||
'::FFFF:129.144.52.38',
|
||||
'fe80:0:0:0:204:61ff:254.157.241.86',
|
||||
'fe80::204:61ff:254.157.241.86',
|
||||
'::ffff:12.34.56.78',
|
||||
'::ffff:192.0.2.128',
|
||||
'2001:0DB8:0000:CD30:0000:0000:0000:0000/60',
|
||||
'2001:0DB8::CD30:0:0:0:0/60',
|
||||
'2001:0DB8:0:CD30::/60',
|
||||
'::/128',
|
||||
'::1/128',
|
||||
'FF00::/8',
|
||||
'FE80::/10',
|
||||
'FEC0::/10',
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156',
|
||||
'fe80:0:0:0:204:61ff:fe9d:f156',
|
||||
'fe80::204:61ff:fe9d:f156',
|
||||
'::1',
|
||||
'fe80::',
|
||||
'fe80::1',
|
||||
'::ffff:c000:280',
|
||||
'2001:0db8:85a3:0000:0000:8a2e:0370:7334',
|
||||
'2001:db8:85a3:0:0:8a2e:370:7334',
|
||||
'2001:db8:85a3::8a2e:370:7334',
|
||||
'2001:0db8:0000:0000:0000:0000:1428:57ab',
|
||||
'2001:0db8:0000:0000:0000::1428:57ab',
|
||||
'2001:0db8:0:0:0:0:1428:57ab',
|
||||
'2001:0db8:0:0::1428:57ab',
|
||||
'2001:0db8::1428:57ab',
|
||||
'2001:db8::1428:57ab',
|
||||
'0000:0000:0000:0000:0000:0000:0000:0001',
|
||||
'::1',
|
||||
'::ffff:0c22:384e',
|
||||
'2001:0db8:1234:0000:0000:0000:0000:0000',
|
||||
'2001:0db8:1234:ffff:ffff:ffff:ffff:ffff',
|
||||
'2001:db8:a::123',
|
||||
'fe80::',
|
||||
'1111:2222:3333:4444:5555:6666:7777:8888',
|
||||
'1111:2222:3333:4444:5555:6666:7777::',
|
||||
'1111:2222:3333:4444:5555:6666::',
|
||||
'1111:2222:3333:4444:5555::',
|
||||
'1111:2222:3333:4444::',
|
||||
'1111:2222:3333::',
|
||||
'1111:2222::',
|
||||
'1111::',
|
||||
'::',
|
||||
'1111:2222:3333:4444:5555:6666::8888',
|
||||
'1111:2222:3333:4444:5555::8888',
|
||||
'1111:2222:3333:4444::8888',
|
||||
'1111:2222:3333::8888',
|
||||
'1111:2222::8888',
|
||||
'1111::8888',
|
||||
'::8888',
|
||||
'1111:2222:3333:4444:5555::7777:8888',
|
||||
'1111:2222:3333:4444::7777:8888',
|
||||
'1111:2222:3333::7777:8888',
|
||||
'1111:2222::7777:8888',
|
||||
'1111::7777:8888',
|
||||
'::7777:8888',
|
||||
'1111:2222:3333:4444::6666:7777:8888',
|
||||
'1111:2222:3333::6666:7777:8888',
|
||||
'1111:2222::6666:7777:8888',
|
||||
'1111::6666:7777:8888',
|
||||
'::6666:7777:8888',
|
||||
'1111:2222:3333::5555:6666:7777:8888',
|
||||
'1111:2222::5555:6666:7777:8888',
|
||||
'1111::5555:6666:7777:8888',
|
||||
'::5555:6666:7777:8888',
|
||||
'1111:2222::4444:5555:6666:7777:8888',
|
||||
'1111::4444:5555:6666:7777:8888',
|
||||
'::4444:5555:6666:7777:8888',
|
||||
'1111::3333:4444:5555:6666:7777:8888',
|
||||
'::3333:4444:5555:6666:7777:8888',
|
||||
'::2222:3333:4444:5555:6666:7777:8888',
|
||||
'1111:2222:3333:4444:5555:6666:123.123.123.123',
|
||||
'1111:2222:3333:4444:5555::123.123.123.123',
|
||||
'1111:2222:3333:4444::123.123.123.123',
|
||||
'1111:2222:3333::123.123.123.123',
|
||||
'1111:2222::123.123.123.123',
|
||||
'1111::123.123.123.123',
|
||||
'::123.123.123.123',
|
||||
'1111:2222:3333:4444::6666:123.123.123.123',
|
||||
'1111:2222:3333::6666:123.123.123.123',
|
||||
'1111:2222::6666:123.123.123.123',
|
||||
'1111::6666:123.123.123.123',
|
||||
'::6666:123.123.123.123',
|
||||
'1111:2222:3333::5555:6666:123.123.123.123',
|
||||
'1111:2222::5555:6666:123.123.123.123',
|
||||
'1111::5555:6666:123.123.123.123',
|
||||
'::5555:6666:123.123.123.123',
|
||||
'1111:2222::4444:5555:6666:123.123.123.123',
|
||||
'1111::4444:5555:6666:123.123.123.123',
|
||||
'::4444:5555:6666:123.123.123.123',
|
||||
'1111::3333:4444:5555:6666:123.123.123.123',
|
||||
'::2222:3333:4444:5555:6666:123.123.123.123',
|
||||
'::0:0:0:0:0:0:0',
|
||||
'::0:0:0:0:0:0',
|
||||
'::0:0:0:0:0',
|
||||
'::0:0:0:0',
|
||||
'::0:0:0',
|
||||
'::0:0',
|
||||
'::0',
|
||||
'0:0:0:0:0:0:0::',
|
||||
'0:0:0:0:0:0::',
|
||||
'0:0:0:0:0::',
|
||||
'0:0:0:0::',
|
||||
'0:0:0::',
|
||||
'0:0::',
|
||||
'0::',
|
||||
'0:a:b:c:d:e:f::',
|
||||
'::0:a:b:c:d:e:f',
|
||||
'a:b:c:d:e:f:0::'
|
||||
]
|
||||
|
||||
const v6not = [
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156/129',
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156/a',
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156/√',
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156/00',
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156/03',
|
||||
'fe80:0000:0000:0000:0204:61ff:fe9d:f156/sdfsdfs',
|
||||
'sssssss::sssssss', // test for regression of badly escaped regex
|
||||
// test cases from Dartware IPv6 Regex
|
||||
'2001:DB8:0:0:8:800:200C:417A:221',
|
||||
'FF01::101::2',
|
||||
'02001:0000:1234:0000:0000:C1C0:ABCD:0876',
|
||||
'2001:0000:1234:0000:00001:C1C0:ABCD:0876',
|
||||
'2001:0000:1234:0000:0000:C1C0:ABCD:0876 0',
|
||||
'2001:0000:1234: 0000:0000:C1C0:ABCD:0876',
|
||||
'3ffe:0b00:0000:0001:0000:0000:000a',
|
||||
'FF02:0000:0000:0000:0000:0000:0000:0000:0001',
|
||||
'3ffe:b00::1::a',
|
||||
'::1111:2222:3333:4444:5555:6666::',
|
||||
'1:2:3::4:5::7:8',
|
||||
'12345::6:7:8',
|
||||
'1::5:400.2.3.4',
|
||||
'1::5:260.2.3.4',
|
||||
'1::5:256.2.3.4',
|
||||
'1::5:1.256.3.4',
|
||||
'1::5:1.2.256.4',
|
||||
'1::5:1.2.3.256',
|
||||
'1::5:300.2.3.4',
|
||||
'1::5:1.300.3.4',
|
||||
'1::5:1.2.300.4',
|
||||
'1::5:1.2.3.300',
|
||||
'1::5:900.2.3.4',
|
||||
'1::5:1.900.3.4',
|
||||
'1::5:1.2.900.4',
|
||||
'1::5:1.2.3.900',
|
||||
'1::5:300.300.300.300',
|
||||
'1::5:3000.30.30.30',
|
||||
'1::400.2.3.4',
|
||||
'1::260.2.3.4',
|
||||
'1::256.2.3.4',
|
||||
'1::1.256.3.4',
|
||||
'1::1.2.256.4',
|
||||
'1::1.2.3.256',
|
||||
'1::300.2.3.4',
|
||||
'1::1.300.3.4',
|
||||
'1::1.2.300.4',
|
||||
'1::1.2.3.300',
|
||||
'1::900.2.3.4',
|
||||
'1::1.900.3.4',
|
||||
'1::1.2.900.4',
|
||||
'1::1.2.3.900',
|
||||
'1::300.300.300.300',
|
||||
'1::3000.30.30.30',
|
||||
'::400.2.3.4',
|
||||
'::260.2.3.4',
|
||||
'::256.2.3.4',
|
||||
'::1.256.3.4',
|
||||
'::1.2.256.4',
|
||||
'::1.2.3.256',
|
||||
'::300.2.3.4',
|
||||
'::1.300.3.4',
|
||||
'::1.2.300.4',
|
||||
'::1.2.3.300',
|
||||
'::900.2.3.4',
|
||||
'::1.900.3.4',
|
||||
'::1.2.900.4',
|
||||
'::1.2.3.900',
|
||||
'::300.300.300.300',
|
||||
'::3000.30.30.30',
|
||||
'2001:1:1:1:1:1:255Z255X255Y255',
|
||||
'::ffff:192x168.1.26',
|
||||
'::ffff:2.3.4',
|
||||
'::ffff:257.1.2.3',
|
||||
'1.2.3.4',
|
||||
'1.2.3.4:1111:2222:3333:4444::5555',
|
||||
'1.2.3.4:1111:2222:3333::5555',
|
||||
'1.2.3.4:1111:2222::5555',
|
||||
'1.2.3.4:1111::5555',
|
||||
'1.2.3.4::5555',
|
||||
'1.2.3.4::',
|
||||
'fe80:0000:0000:0000:0204:61ff:254.157.241.086',
|
||||
'XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:1.2.3.4',
|
||||
'1111:2222:3333:4444:5555:6666:00.00.00.00',
|
||||
'1111:2222:3333:4444:5555:6666:000.000.000.000',
|
||||
'1111:2222:3333:4444:5555:6666:256.256.256.256',
|
||||
'124.15.6.89/60',
|
||||
':',
|
||||
'1111:2222:3333:4444::5555:',
|
||||
'1111:2222:3333::5555:',
|
||||
'1111:2222::5555:',
|
||||
'1111::5555:',
|
||||
'::5555:',
|
||||
':::',
|
||||
'1111:',
|
||||
':',
|
||||
':1111:2222:3333:4444::5555',
|
||||
':1111:2222:3333::5555',
|
||||
':1111:2222::5555',
|
||||
':1111::5555',
|
||||
':::5555',
|
||||
':::',
|
||||
'123',
|
||||
'ldkfj',
|
||||
'2001::FFD3::57ab',
|
||||
'2001:db8:85a3::8a2e:37023:7334',
|
||||
'2001:db8:85a3::8a2e:370k:7334',
|
||||
'1:2:3:4:5:6:7:8:9',
|
||||
'1::2::3',
|
||||
'1:::3:4:5',
|
||||
'1:2:3::4:5:6:7:8:9',
|
||||
'XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX',
|
||||
'1111:2222:3333:4444:5555:6666:7777:8888:9999',
|
||||
'1111:2222:3333:4444:5555:6666:7777:8888::',
|
||||
'::2222:3333:4444:5555:6666:7777:8888:9999',
|
||||
'1111:2222:3333:4444:5555:6666:7777',
|
||||
'1111:2222:3333:4444:5555:6666',
|
||||
'1111:2222:3333:4444:5555',
|
||||
'1111:2222:3333:4444',
|
||||
'1111:2222:3333',
|
||||
'1111:2222',
|
||||
'1111',
|
||||
'11112222:3333:4444:5555:6666:7777:8888',
|
||||
'1111:22223333:4444:5555:6666:7777:8888',
|
||||
'1111:2222:33334444:5555:6666:7777:8888',
|
||||
'1111:2222:3333:44445555:6666:7777:8888',
|
||||
'1111:2222:3333:4444:55556666:7777:8888',
|
||||
'1111:2222:3333:4444:5555:66667777:8888',
|
||||
'1111:2222:3333:4444:5555:6666:77778888',
|
||||
'1111:2222:3333:4444:5555:6666:7777:8888:',
|
||||
'1111:2222:3333:4444:5555:6666:7777:',
|
||||
'1111:2222:3333:4444:5555:6666:',
|
||||
'1111:2222:3333:4444:5555:',
|
||||
'1111:2222:3333:4444:',
|
||||
'1111:2222:3333:',
|
||||
'1111:2222:',
|
||||
'1111:',
|
||||
':',
|
||||
':8888',
|
||||
':7777:8888',
|
||||
':6666:7777:8888',
|
||||
':5555:6666:7777:8888',
|
||||
':4444:5555:6666:7777:8888',
|
||||
':3333:4444:5555:6666:7777:8888',
|
||||
':2222:3333:4444:5555:6666:7777:8888',
|
||||
':1111:2222:3333:4444:5555:6666:7777:8888',
|
||||
':::2222:3333:4444:5555:6666:7777:8888',
|
||||
'1111:::3333:4444:5555:6666:7777:8888',
|
||||
'1111:2222:::4444:5555:6666:7777:8888',
|
||||
'1111:2222:3333:::5555:6666:7777:8888',
|
||||
'1111:2222:3333:4444:::6666:7777:8888',
|
||||
'1111:2222:3333:4444:5555:::7777:8888',
|
||||
'1111:2222:3333:4444:5555:6666:::8888',
|
||||
'1111:2222:3333:4444:5555:6666:7777:::',
|
||||
'::2222::4444:5555:6666:7777:8888',
|
||||
'::2222:3333::5555:6666:7777:8888',
|
||||
'::2222:3333:4444::6666:7777:8888',
|
||||
'::2222:3333:4444:5555::7777:8888',
|
||||
'::2222:3333:4444:5555:7777::8888',
|
||||
'::2222:3333:4444:5555:7777:8888::',
|
||||
'1111::3333::5555:6666:7777:8888',
|
||||
'1111::3333:4444::6666:7777:8888',
|
||||
'1111::3333:4444:5555::7777:8888',
|
||||
'1111::3333:4444:5555:6666::8888',
|
||||
'1111::3333:4444:5555:6666:7777::',
|
||||
'1111:2222::4444::6666:7777:8888',
|
||||
'1111:2222::4444:5555::7777:8888',
|
||||
'1111:2222::4444:5555:6666::8888',
|
||||
'1111:2222::4444:5555:6666:7777::',
|
||||
'1111:2222:3333::5555::7777:8888',
|
||||
'1111:2222:3333::5555:6666::8888',
|
||||
'1111:2222:3333::5555:6666:7777::',
|
||||
'1111:2222:3333:4444::6666::8888',
|
||||
'1111:2222:3333:4444::6666:7777::',
|
||||
'1111:2222:3333:4444:5555::7777::',
|
||||
'1111:2222:3333:4444:5555:6666:7777:8888:1.2.3.4',
|
||||
'1111:2222:3333:4444:5555:6666:7777:1.2.3.4',
|
||||
'1111:2222:3333:4444:5555:6666::1.2.3.4',
|
||||
'::2222:3333:4444:5555:6666:7777:1.2.3.4',
|
||||
'1111:2222:3333:4444:5555:6666:1.2.3.4.5',
|
||||
'1111:2222:3333:4444:5555:1.2.3.4',
|
||||
'1111:2222:3333:4444:1.2.3.4',
|
||||
'1111:2222:3333:1.2.3.4',
|
||||
'1111:2222:1.2.3.4',
|
||||
'1111:1.2.3.4',
|
||||
'1.2.3.4',
|
||||
'11112222:3333:4444:5555:6666:1.2.3.4',
|
||||
'1111:22223333:4444:5555:6666:1.2.3.4',
|
||||
'1111:2222:33334444:5555:6666:1.2.3.4',
|
||||
'1111:2222:3333:44445555:6666:1.2.3.4',
|
||||
'1111:2222:3333:4444:55556666:1.2.3.4',
|
||||
'1111:2222:3333:4444:5555:66661.2.3.4',
|
||||
'1111:2222:3333:4444:5555:6666:255255.255.255',
|
||||
'1111:2222:3333:4444:5555:6666:255.255255.255',
|
||||
'1111:2222:3333:4444:5555:6666:255.255.255255',
|
||||
':1.2.3.4',
|
||||
':6666:1.2.3.4',
|
||||
':5555:6666:1.2.3.4',
|
||||
':4444:5555:6666:1.2.3.4',
|
||||
':3333:4444:5555:6666:1.2.3.4',
|
||||
':2222:3333:4444:5555:6666:1.2.3.4',
|
||||
':1111:2222:3333:4444:5555:6666:1.2.3.4',
|
||||
':::2222:3333:4444:5555:6666:1.2.3.4',
|
||||
'1111:::3333:4444:5555:6666:1.2.3.4',
|
||||
'1111:2222:::4444:5555:6666:1.2.3.4',
|
||||
'1111:2222:3333:::5555:6666:1.2.3.4',
|
||||
'1111:2222:3333:4444:::6666:1.2.3.4',
|
||||
'1111:2222:3333:4444:5555:::1.2.3.4',
|
||||
'::2222::4444:5555:6666:1.2.3.4',
|
||||
'::2222:3333::5555:6666:1.2.3.4',
|
||||
'::2222:3333:4444::6666:1.2.3.4',
|
||||
'::2222:3333:4444:5555::1.2.3.4',
|
||||
'1111::3333::5555:6666:1.2.3.4',
|
||||
'1111::3333:4444::6666:1.2.3.4',
|
||||
'1111::3333:4444:5555::1.2.3.4',
|
||||
'1111:2222::4444::6666:1.2.3.4',
|
||||
'1111:2222::4444:5555::1.2.3.4',
|
||||
'1111:2222:3333::5555::1.2.3.4',
|
||||
'::.',
|
||||
'::..',
|
||||
'::...',
|
||||
'::1...',
|
||||
'::1.2..',
|
||||
'::1.2.3.',
|
||||
'::.2..',
|
||||
'::.2.3.',
|
||||
'::.2.3.4',
|
||||
'::..3.',
|
||||
'::..3.4',
|
||||
'::...4',
|
||||
':1111:2222:3333:4444:5555:6666:7777::',
|
||||
':1111:2222:3333:4444:5555:6666::',
|
||||
':1111:2222:3333:4444:5555::',
|
||||
':1111:2222:3333:4444::',
|
||||
':1111:2222:3333::',
|
||||
':1111:2222::',
|
||||
':1111::',
|
||||
':::',
|
||||
':1111:2222:3333:4444:5555:6666::8888',
|
||||
':1111:2222:3333:4444:5555::8888',
|
||||
':1111:2222:3333:4444::8888',
|
||||
':1111:2222:3333::8888',
|
||||
':1111:2222::8888',
|
||||
':1111::8888',
|
||||
':::8888',
|
||||
':1111:2222:3333:4444:5555::7777:8888',
|
||||
':1111:2222:3333:4444::7777:8888',
|
||||
':1111:2222:3333::7777:8888',
|
||||
':1111:2222::7777:8888',
|
||||
':1111::7777:8888',
|
||||
':::7777:8888',
|
||||
':1111:2222:3333:4444::6666:7777:8888',
|
||||
':1111:2222:3333::6666:7777:8888',
|
||||
':1111:2222::6666:7777:8888',
|
||||
':1111::6666:7777:8888',
|
||||
':::6666:7777:8888',
|
||||
':1111:2222:3333::5555:6666:7777:8888',
|
||||
':1111:2222::5555:6666:7777:8888',
|
||||
':1111::5555:6666:7777:8888',
|
||||
':::5555:6666:7777:8888',
|
||||
':1111:2222::4444:5555:6666:7777:8888',
|
||||
':1111::4444:5555:6666:7777:8888',
|
||||
':::4444:5555:6666:7777:8888',
|
||||
':1111::3333:4444:5555:6666:7777:8888',
|
||||
':::3333:4444:5555:6666:7777:8888',
|
||||
':::2222:3333:4444:5555:6666:7777:8888',
|
||||
':1111:2222:3333:4444:5555:6666:1.2.3.4',
|
||||
':1111:2222:3333:4444:5555::1.2.3.4',
|
||||
':1111:2222:3333:4444::1.2.3.4',
|
||||
':1111:2222:3333::1.2.3.4',
|
||||
':1111:2222::1.2.3.4',
|
||||
':1111::1.2.3.4',
|
||||
':::1.2.3.4',
|
||||
':1111:2222:3333:4444::6666:1.2.3.4',
|
||||
':1111:2222:3333::6666:1.2.3.4',
|
||||
':1111:2222::6666:1.2.3.4',
|
||||
':1111::6666:1.2.3.4',
|
||||
':::6666:1.2.3.4',
|
||||
':1111:2222:3333::5555:6666:1.2.3.4',
|
||||
':1111:2222::5555:6666:1.2.3.4',
|
||||
':1111::5555:6666:1.2.3.4',
|
||||
':::5555:6666:1.2.3.4',
|
||||
':1111:2222::4444:5555:6666:1.2.3.4',
|
||||
':1111::4444:5555:6666:1.2.3.4',
|
||||
':::4444:5555:6666:1.2.3.4',
|
||||
':1111::3333:4444:5555:6666:1.2.3.4',
|
||||
':::2222:3333:4444:5555:6666:1.2.3.4',
|
||||
'1111:2222:3333:4444:5555:6666:7777:::',
|
||||
'1111:2222:3333:4444:5555:6666:::',
|
||||
'1111:2222:3333:4444:5555:::',
|
||||
'1111:2222:3333:4444:::',
|
||||
'1111:2222:3333:::',
|
||||
'1111:2222:::',
|
||||
'1111:::',
|
||||
':::',
|
||||
'1111:2222:3333:4444:5555:6666::8888:',
|
||||
'1111:2222:3333:4444:5555::8888:',
|
||||
'1111:2222:3333:4444::8888:',
|
||||
'1111:2222:3333::8888:',
|
||||
'1111:2222::8888:',
|
||||
'1111::8888:',
|
||||
'::8888:',
|
||||
'1111:2222:3333:4444:5555::7777:8888:',
|
||||
'1111:2222:3333:4444::7777:8888:',
|
||||
'1111:2222:3333::7777:8888:',
|
||||
'1111:2222::7777:8888:',
|
||||
'1111::7777:8888:',
|
||||
'::7777:8888:',
|
||||
'1111:2222:3333:4444::6666:7777:8888:',
|
||||
'1111:2222:3333::6666:7777:8888:',
|
||||
'1111:2222::6666:7777:8888:',
|
||||
'1111::6666:7777:8888:',
|
||||
'::6666:7777:8888:',
|
||||
'1111:2222:3333::5555:6666:7777:8888:',
|
||||
'1111:2222::5555:6666:7777:8888:',
|
||||
'1111::5555:6666:7777:8888:',
|
||||
'::5555:6666:7777:8888:',
|
||||
'1111:2222::4444:5555:6666:7777:8888:',
|
||||
'1111::4444:5555:6666:7777:8888:',
|
||||
'::4444:5555:6666:7777:8888:',
|
||||
'1111::3333:4444:5555:6666:7777:8888:',
|
||||
'::3333:4444:5555:6666:7777:8888:',
|
||||
'::2222:3333:4444:5555:6666:7777:8888:',
|
||||
'\':10.0.0.1'
|
||||
]
|
||||
|
||||
test('cidr v4', (t) => {
|
||||
v4.forEach((string) => {
|
||||
t.true(cidr.test(string))
|
||||
})
|
||||
|
||||
v4not.forEach((string) => {
|
||||
t.false(cidrv4.test(string))
|
||||
})
|
||||
})
|
||||
|
||||
test('cidr v6', (t) => {
|
||||
v6.forEach((string) => {
|
||||
t.true(cidrv6.test(string))
|
||||
})
|
||||
|
||||
v6not.forEach((string) => {
|
||||
t.false(cidrv6.test(string))
|
||||
})
|
||||
})
|
||||
|
9
node_modules/get-ip-range/CHANGELOG.md
generated
vendored
Normal file
9
node_modules/get-ip-range/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
## v2.1.1
|
||||
- Fix error message
|
||||
|
||||
## v2.1.0
|
||||
- Remove debugger
|
||||
|
||||
## v2.0.0
|
||||
- IPv6 Support
|
||||
- Hyphenated range support
|
7
node_modules/get-ip-range/LICENSE
generated
vendored
Normal file
7
node_modules/get-ip-range/LICENSE
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2017 Joe Schofield
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
79
node_modules/get-ip-range/README.md
generated
vendored
Normal file
79
node_modules/get-ip-range/README.md
generated
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
# get-ip-range
|
||||
|
||||
Simple utility to convert either CIDR notation, a hyphenated IP range, or two IP addresses to an array of the range of IP addresses.
|
||||
|
||||
----
|
||||
|
||||
<a href="https://nodei.co/npm/get-ip-range/"><img src="https://nodei.co/npm/get-ip-range.png?downloads=true"></a>
|
||||
|
||||
[](https://coveralls.io/github/JoeScho/getIPRange?branch=master)[](https://github.com/JoeScho/getIPRange/blob/master/LICENSE)
|
||||
|
||||
----
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
$ npm i get-ip-range
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
## Accepted formats
|
||||
### IPv4
|
||||
* CIDR `"x.x.x.x/x"`
|
||||
* Range `"x.x.x.x-x.x.x.x"`
|
||||
* Two IPs `"x.x.x.x, x.x.x.x"`
|
||||
|
||||
### IPv6
|
||||
* CIDR `"x:x:x:x:x:x:x:x/x"`
|
||||
* Range `"::x:x:x-::x:x:x"`
|
||||
* Two IPs `"::x:x:x", "::x:x:x"`
|
||||
|
||||
**N.B. Shorthand IPv6 is supported**
|
||||
|
||||
----
|
||||
|
||||
## Usage
|
||||
```js
|
||||
const getIPRange = require('get-ip-range');
|
||||
|
||||
const ipv4CIDR = getIPRange('192.168.1.134/29');
|
||||
const ipv4Range = getIPRange('192.168.1.128-192.168.1.135');
|
||||
const twoIPv4 = getIPRange('192.168.1.128', '192.168.1.135');
|
||||
|
||||
// All return:
|
||||
//
|
||||
// [
|
||||
// '192.168.1.128',
|
||||
// '192.168.1.129',
|
||||
// '192.168.1.130',
|
||||
// '192.168.1.131',
|
||||
// '192.168.1.132',
|
||||
// '192.168.1.133',
|
||||
// '192.168.1.134',
|
||||
// '192.168.1.135',
|
||||
// ]
|
||||
//
|
||||
|
||||
const ipv6CIDR = getIPRange('0:0:0:0:0:ffff:102:304/126');
|
||||
const ipv6Range = getIPRange('::ffff:102:304-::ffff:102:307');
|
||||
const twoIPv6 = getIPRange('::ffff:102:304', '::ffff:102:307');
|
||||
|
||||
// All return:
|
||||
//
|
||||
// [
|
||||
// '::ffff:102:304',
|
||||
// '::ffff:102:305',
|
||||
// '::ffff:102:306',
|
||||
// '::ffff:102:307',
|
||||
// ]
|
||||
//
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
**Errors**
|
||||
|
||||
If the supplied IP address(es) are invalid, the request will **throw an [error](https://nodejs.org/api/errors.html#errors_class_error)**. Please handle errors appropriately.
|
||||
|
||||
----
|
79
node_modules/get-ip-range/index.js
generated
vendored
Normal file
79
node_modules/get-ip-range/index.js
generated
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
const ip = require('ip');
|
||||
const ipAddress = require('ip-address')
|
||||
const { cidrv4, cidrv6 } = require('cidr-regex');
|
||||
|
||||
const errorMessage = new Error('IP supplied is not valid');
|
||||
|
||||
const getRangev4 = (ip1, ip2) => {
|
||||
const ips = [];
|
||||
|
||||
let firstAddressLong = ip.toLong(ip1);
|
||||
const lastAddressLong = ip.toLong(ip2);
|
||||
|
||||
for (firstAddressLong; firstAddressLong <= lastAddressLong; firstAddressLong++)
|
||||
ips.push(ip.fromLong(firstAddressLong));
|
||||
|
||||
return ips;
|
||||
}
|
||||
|
||||
const getRangev6 = (ip1, ip2) => {
|
||||
const ips = [];
|
||||
|
||||
const firstAddress = new ipAddress.Address6(ip1);
|
||||
const lastAddress = new ipAddress.Address6(ip2);
|
||||
|
||||
for (let i = firstAddress.bigInteger(); i <= lastAddress.bigInteger(); i++) {
|
||||
ips.push(ipAddress.Address6.fromBigInteger(i).correctForm());
|
||||
}
|
||||
|
||||
return ips;
|
||||
}
|
||||
|
||||
const isCIDR = ip => {
|
||||
return ip.indexOf('/') !== -1
|
||||
}
|
||||
|
||||
const isRange = ip => {
|
||||
return ip.indexOf('-') !== -1
|
||||
}
|
||||
|
||||
const convert = (cidrIp, ip2) => {
|
||||
const ip1v4 = new ipAddress.Address4(cidrIp);
|
||||
const ip1v6 = new ipAddress.Address6(cidrIp);
|
||||
|
||||
if (ip2) {
|
||||
const ip2v4 = new ipAddress.Address4(ip2);
|
||||
const ip2v6 = new ipAddress.Address6(ip2);
|
||||
|
||||
if (ip1v4.valid && ip2v4.valid && !isCIDR(cidrIp) && !isCIDR(ip2)) {
|
||||
return getRangev4(cidrIp, ip2);
|
||||
}
|
||||
|
||||
if (ip1v6.valid && ip2v6.valid) {
|
||||
return getRangev6(cidrIp, ip2);
|
||||
}
|
||||
} else {
|
||||
if (ip1v4.valid) {
|
||||
const subnet = ip.cidrSubnet(cidrIp);
|
||||
|
||||
const firstAddress = subnet.firstAddress;
|
||||
const lastAddress = subnet.lastAddress;
|
||||
|
||||
return getRangev4(firstAddress, lastAddress);
|
||||
}
|
||||
|
||||
if (ip1v6.valid) {
|
||||
const IPv6 = new ipAddress.Address6(cidrIp);
|
||||
return getRangev6(IPv6.startAddress().correctForm(), IPv6.endAddress().correctForm());
|
||||
}
|
||||
|
||||
if (isRange(cidrIp)) {
|
||||
const [ firstAddress, lastAddress ] = cidrIp.split('-');
|
||||
return convert(firstAddress, lastAddress);
|
||||
}
|
||||
}
|
||||
|
||||
throw errorMessage;
|
||||
}
|
||||
|
||||
module.exports = convert;
|
69
node_modules/get-ip-range/package.json
generated
vendored
Normal file
69
node_modules/get-ip-range/package.json
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
{
|
||||
"name": "get-ip-range",
|
||||
"version": "2.1.1",
|
||||
"description": "Simple utility to convert either CIDR notation or two IP addresses to an array of the range of IP addresses",
|
||||
"main": "index.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "nyc --reporter=html --reporter=text mocha *.test.js",
|
||||
"jshint": "jshint *.js *.test.js",
|
||||
"code-style": "jscs -p airbnb --fix *.js *.test.js",
|
||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||
"check-coverage": "nyc check-coverage --statements 100 --functions 100 --lines 100 --branches 100",
|
||||
"open-coverage": "open coverage/index.html"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"CIDR",
|
||||
"IP"
|
||||
],
|
||||
"author": "@JoeScho <joeschofield@live.co.uk>",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/JoeScho/get-ip-range/issues"
|
||||
},
|
||||
"homepage": "https://github.com/JoeScho/get-ip-range#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/JoeScho/get-ip-range.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^4.1.2",
|
||||
"coveralls": "^3.0.2",
|
||||
"jscs": "^3.0.7",
|
||||
"jshint": "^2.10.1",
|
||||
"mocha": "^5.2.0",
|
||||
"nyc": "^14.1.1"
|
||||
},
|
||||
"pre-commit": [
|
||||
"jshint",
|
||||
"code-style",
|
||||
"test",
|
||||
"check-coverage"
|
||||
],
|
||||
"jshintConfig": {
|
||||
"boss": true,
|
||||
"node": true,
|
||||
"strict": false,
|
||||
"smarttabs": true,
|
||||
"maxlen": 100,
|
||||
"newcap": false,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"onecase": true,
|
||||
"indent": 2,
|
||||
"sub": true,
|
||||
"esversion": 8
|
||||
},
|
||||
"dependencies": {
|
||||
"cidr-regex": "^1.0.7",
|
||||
"ip": "^1.1.5",
|
||||
"ip-address": "^6.1.0"
|
||||
}
|
||||
}
|
19
node_modules/ip-address/LICENSE
generated
vendored
Normal file
19
node_modules/ip-address/LICENSE
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (C) 2011 by Beau Gunderson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
96
node_modules/ip-address/README.md
generated
vendored
Normal file
96
node_modules/ip-address/README.md
generated
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
[![travis]](http://travis-ci.org/beaugunderson/ip-address)
|
||||
[![codecov]](https://codecov.io/github/beaugunderson/ip-address?branch=master)
|
||||
[![downloads]](https://www.npmjs.com/package/ip-address)
|
||||
[![npm]](https://www.npmjs.com/package/ip-address)
|
||||
[![greenkeeper]](https://greenkeeper.io/)
|
||||
|
||||
[codecov]: https://codecov.io/github/beaugunderson/ip-address/coverage.svg?branch=master
|
||||
[downloads]: https://img.shields.io/npm/dm/ip-address.svg
|
||||
[greenkeeper]: https://badges.greenkeeper.io/beaugunderson/ip-address.svg
|
||||
[npm]: https://img.shields.io/npm/v/ip-address.svg
|
||||
[travis]: https://img.shields.io/travis/beaugunderson/ip-address.svg
|
||||
|
||||
## ip-address
|
||||
|
||||
`ip-address` is a library for validating and manipulating IPv4 and IPv6
|
||||
addresses in JavaScript.
|
||||
|
||||
### Documentation
|
||||
|
||||
Documentation is available at [ip-address.js.org](http://ip-address.js.org/).
|
||||
|
||||
### Examples
|
||||
|
||||
```js
|
||||
var Address6 = require('ip-address').Address6;
|
||||
|
||||
var address = new Address6('2001:0:ce49:7601:e866:efff:62c3:fffe');
|
||||
|
||||
address.isValid(); // true
|
||||
|
||||
var teredo = address.inspectTeredo();
|
||||
|
||||
teredo.client4; // '157.60.0.1'
|
||||
```
|
||||
|
||||
### Features
|
||||
|
||||
- Parsing of all IPv6 notations
|
||||
- Parsing of IPv6 addresses and ports from URLs with `Address6.fromURL(url)`
|
||||
- Validity checking
|
||||
- Decoding of the [Teredo
|
||||
information](http://en.wikipedia.org/wiki/Teredo_tunneling#IPv6_addressing)
|
||||
in an address
|
||||
- Whether one address is a valid subnet of another
|
||||
- What special properties a given address has (multicast prefix, unique
|
||||
local address prefix, etc.)
|
||||
- Number of subnets of a certain size in a given address
|
||||
- Display methods
|
||||
- Hex, binary, and decimal
|
||||
- Canonical form
|
||||
- Correct form
|
||||
- IPv4-compatible (i.e. `::ffff:192.168.0.1`)
|
||||
- Works in [node](http://nodejs.org/) and the browser (with browserify)
|
||||
- ~1,600 test cases
|
||||
|
||||
### Used by
|
||||
|
||||
- [anon](https://github.com/edsu/anon) which powers
|
||||
[@congressedits](https://twitter.com/congressedits), among
|
||||
[many others](https://github.com/edsu/anon#community)
|
||||
- [base85](https://github.com/noseglid/base85): base85 encoding/decoding
|
||||
- [contrail-web-core](https://github.com/Juniper/contrail-web-core): part of
|
||||
Contrail, a network virtualization solution made by Juniper Networks
|
||||
- [dhcpjs](https://github.com/apaprocki/node-dhcpjs): a DHCP client and server
|
||||
- [epochtalk](https://github.com/epochtalk/epochtalk): next generation forum
|
||||
software
|
||||
- [geoip-web](https://github.com/tfrce/node-geoip-web): a server for
|
||||
quickly geolocating IP addresses
|
||||
- [hexabus](https://github.com/mysmartgrid/hexabus): an IPv6-based home
|
||||
automation bus
|
||||
- [hubot-deploy](https://github.com/atmos/hubot-deploy): GitHub Flow via hubot
|
||||
- [heroku-portscanner](https://github.com/robison/heroku-portscanner): nmap
|
||||
hosted on Heroku
|
||||
- [ipfs-swarm](https://github.com/diasdavid/node-ipfs-swarm): a swarm
|
||||
implementation based on IPFS
|
||||
- [javascript-x-server](https://github.com/GothAck/javascript-x-server): an X
|
||||
server written in JavaScript
|
||||
- [libnmap](https://github.com/jas-/node-libnmap): a node API for nmap
|
||||
- [mail-io](https://github.com/mofux/mail-io): a lightweight SMTP server
|
||||
- [maxmind-db-reader](https://github.com/PaddeK/node-maxmind-db): a library for
|
||||
reading MaxMind database files
|
||||
- [proxy-protocol-v2](https://github.com/ably/proxy-protocol-v2): a proxy
|
||||
protocol encoder/decoder built by [Ably](https://www.ably.io/)
|
||||
- [Samsara](https://github.com/mariusGundersen/Samsara): a Docker web interface
|
||||
- [sis-api](https://github.com/sis-cmdb/sis-api): a configuration management
|
||||
database API
|
||||
- [socks5-client](https://github.com/mattcg/socks5-client): a SOCKS v5 client
|
||||
- [socksified](https://github.com/vially/node-socksified): a SOCKS v5 client
|
||||
- [socksv5](https://github.com/mscdex/socksv5): a SOCKS v5 server/client
|
||||
- [ssdapi](https://github.com/rsolomou/ssdapi): an API created by the
|
||||
University of Portsmouth
|
||||
- [SwitchyOmega](https://github.com/FelisCatus/SwitchyOmega): a [Chrome
|
||||
extension](https://chrome.google.com/webstore/detail/padekgcemlokbadohgkifijomclgjgif)
|
||||
for switching between multiple proxies with ~311k users!
|
||||
- [swiz](https://github.com/racker/node-swiz): a serialization framework built
|
||||
and used by [Rackspace](http://www.rackspace.com/)
|
8
node_modules/ip-address/ip-address.js
generated
vendored
Normal file
8
node_modules/ip-address/ip-address.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
exports.Address4 = require('./lib/ipv4.js');
|
||||
exports.Address6 = require('./lib/ipv6.js');
|
||||
|
||||
exports.v6 = {
|
||||
helpers: require('./lib/v6/helpers.js')
|
||||
};
|
39
node_modules/ip-address/lib/common.js
generated
vendored
Normal file
39
node_modules/ip-address/lib/common.js
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
// A wrapper function that returns false if the address is not valid; used to
|
||||
// avoid boilerplate checks for `if (!this.valid) { return false; }`
|
||||
var falseIfInvalid = exports.falseIfInvalid = function (fn) {
|
||||
return function () {
|
||||
if (!this.valid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return fn.apply(this, arguments);
|
||||
};
|
||||
};
|
||||
|
||||
exports.isInSubnet = falseIfInvalid(function (address) {
|
||||
if (this.subnetMask < address.subnetMask) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.mask(address.subnetMask) === address.mask()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
exports.isCorrect = function (defaultBits) {
|
||||
return falseIfInvalid(function () {
|
||||
if (this.addressMinusSuffix !== this.correctForm()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.subnetMask === defaultBits && !this.parsedSubnet) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.parsedSubnet === String(this.subnetMask);
|
||||
});
|
||||
};
|
320
node_modules/ip-address/lib/ipv4.js
generated
vendored
Normal file
320
node_modules/ip-address/lib/ipv4.js
generated
vendored
Normal file
@ -0,0 +1,320 @@
|
||||
'use strict';
|
||||
|
||||
var BigInteger = require('jsbn').BigInteger;
|
||||
var common = require('./common.js');
|
||||
var sprintf = require('sprintf-js').sprintf;
|
||||
var padStart = require('lodash.padstart');
|
||||
var repeat = require('lodash.repeat');
|
||||
|
||||
var constants = require('./v4/constants.js');
|
||||
|
||||
/**
|
||||
* Represents an IPv4 address
|
||||
* @class Address4
|
||||
* @param {string} address - An IPv4 address string
|
||||
*/
|
||||
function Address4(address) {
|
||||
this.valid = false;
|
||||
this.address = address;
|
||||
this.groups = constants.GROUPS;
|
||||
|
||||
this.v4 = true;
|
||||
|
||||
this.subnet = '/32';
|
||||
this.subnetMask = 32;
|
||||
|
||||
var subnet = constants.RE_SUBNET_STRING.exec(address);
|
||||
|
||||
if (subnet) {
|
||||
this.parsedSubnet = subnet[0].replace('/', '');
|
||||
this.subnetMask = parseInt(this.parsedSubnet, 10);
|
||||
this.subnet = '/' + this.subnetMask;
|
||||
|
||||
if (this.subnetMask < 0 || this.subnetMask > constants.BITS) {
|
||||
this.valid = false;
|
||||
this.error = 'Invalid subnet mask.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
address = address.replace(constants.RE_SUBNET_STRING, '');
|
||||
}
|
||||
|
||||
this.addressMinusSuffix = address;
|
||||
|
||||
this.parsedAddress = this.parse(address);
|
||||
}
|
||||
|
||||
/*
|
||||
* Parses a v4 address
|
||||
*/
|
||||
Address4.prototype.parse = function (address) {
|
||||
var groups = address.split('.');
|
||||
|
||||
if (address.match(constants.RE_ADDRESS)) {
|
||||
this.valid = true;
|
||||
} else {
|
||||
this.error = 'Invalid IPv4 address.';
|
||||
}
|
||||
|
||||
return groups;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return true if the address is valid
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
Address4.prototype.isValid = function () {
|
||||
return this.valid;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the correct form of an address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
Address4.prototype.correctForm = function () {
|
||||
return this.parsedAddress.map(function (part) {
|
||||
return parseInt(part, 10);
|
||||
}).join('.');
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the address is correct, false otherwise
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
Address4.prototype.isCorrect = common.isCorrect(constants.BITS);
|
||||
|
||||
/**
|
||||
* Converts a hex string to an IPv4 address object
|
||||
* @memberof Address4
|
||||
* @static
|
||||
* @param {string} hex - a hex string to convert
|
||||
* @returns {Address4}
|
||||
*/
|
||||
Address4.fromHex = function (hex) {
|
||||
var padded = padStart(hex.replace(/:/g, ''), 8, '0');
|
||||
var groups = [];
|
||||
var i;
|
||||
|
||||
for (i = 0; i < 8; i += 2) {
|
||||
var h = padded.slice(i, i + 2);
|
||||
|
||||
groups.push(parseInt(h, 16));
|
||||
}
|
||||
|
||||
return new Address4(groups.join('.'));
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts an integer into a IPv4 address object
|
||||
* @memberof Address4
|
||||
* @static
|
||||
* @param {integer} integer - a number to convert
|
||||
* @returns {Address4}
|
||||
*/
|
||||
Address4.fromInteger = function (integer) {
|
||||
return Address4.fromHex(integer.toString(16));
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts an IPv4 address object to a hex string
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
Address4.prototype.toHex = function () {
|
||||
return this.parsedAddress.map(function (part) {
|
||||
return sprintf('%02x', parseInt(part, 10));
|
||||
}).join(':');
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts an IPv4 address object to an array of bytes
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Array}
|
||||
*/
|
||||
Address4.prototype.toArray = function () {
|
||||
return this.parsedAddress.map(function (part) {
|
||||
return parseInt(part, 10);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts an IPv4 address object to an IPv6 address group
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
Address4.prototype.toGroup6 = function () {
|
||||
var output = [];
|
||||
var i;
|
||||
|
||||
for (i = 0; i < constants.GROUPS; i += 2) {
|
||||
var hex = sprintf('%02x%02x',
|
||||
parseInt(this.parsedAddress[i], 10),
|
||||
parseInt(this.parsedAddress[i + 1], 10));
|
||||
|
||||
output.push(sprintf('%x', parseInt(hex, 16)));
|
||||
}
|
||||
|
||||
return output.join(':');
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the address as a BigInteger
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {BigInteger}
|
||||
*/
|
||||
Address4.prototype.bigInteger = function () {
|
||||
if (!this.valid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BigInteger(this.parsedAddress.map(function (n) {
|
||||
return sprintf('%02x', parseInt(n, 10));
|
||||
}).join(''), 16);
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function getting start address.
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {BigInteger}
|
||||
*/
|
||||
Address4.prototype._startAddress = function () {
|
||||
return new BigInteger(
|
||||
this.mask() + repeat('0', constants.BITS - this.subnetMask), 2
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* The first address in the range given by this address' subnet.
|
||||
* Often referred to as the Network Address.
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Address4}
|
||||
*/
|
||||
Address4.prototype.startAddress = function () {
|
||||
return Address4.fromBigInteger(this._startAddress());
|
||||
};
|
||||
|
||||
/**
|
||||
* The first host address in the range given by this address's subnet ie
|
||||
* the first address after the Network Address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Address4}
|
||||
*/
|
||||
Address4.prototype.startAddressExclusive = function () {
|
||||
var adjust = new BigInteger('1');
|
||||
return Address4.fromBigInteger(this._startAddress().add(adjust));
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function getting end address.
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {BigInteger}
|
||||
*/
|
||||
Address4.prototype._endAddress = function () {
|
||||
return new BigInteger(
|
||||
this.mask() + repeat('1', constants.BITS - this.subnetMask), 2
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* The last address in the range given by this address' subnet
|
||||
* Often referred to as the Broadcast
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Address4}
|
||||
*/
|
||||
Address4.prototype.endAddress = function () {
|
||||
return Address4.fromBigInteger(this._endAddress());
|
||||
};
|
||||
|
||||
/**
|
||||
* The last host address in the range given by this address's subnet ie
|
||||
* the last address prior to the Broadcast Address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Address4}
|
||||
*/
|
||||
Address4.prototype.endAddressExclusive = function () {
|
||||
var adjust = new BigInteger('1');
|
||||
return Address4.fromBigInteger(this._endAddress().subtract(adjust));
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a BigInteger to a v4 address object
|
||||
* @memberof Address4
|
||||
* @static
|
||||
* @param {BigInteger} bigInteger - a BigInteger to convert
|
||||
* @returns {Address4}
|
||||
*/
|
||||
Address4.fromBigInteger = function (bigInteger) {
|
||||
return Address4.fromInteger(parseInt(bigInteger.toString(), 10));
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the first n bits of the address, defaulting to the
|
||||
* subnet mask
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
Address4.prototype.mask = function (optionalMask) {
|
||||
if (optionalMask === undefined) {
|
||||
optionalMask = this.subnetMask;
|
||||
}
|
||||
|
||||
return this.getBitsBase2(0, optionalMask);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the bits in the given range as a base-2 string
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {string}
|
||||
*/
|
||||
Address4.prototype.getBitsBase2 = function (start, end) {
|
||||
return this.binaryZeroPad().slice(start, end);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the given address is in the subnet of the current address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
Address4.prototype.isInSubnet = common.isInSubnet;
|
||||
|
||||
/**
|
||||
* Returns true if the given address is a multicast address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
Address4.prototype.isMulticast = function () {
|
||||
return this.isInSubnet(new Address4('224.0.0.0/4'));
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a zero-padded base-2 string representation of the address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {string}
|
||||
*/
|
||||
Address4.prototype.binaryZeroPad = function () {
|
||||
return padStart(this.bigInteger().toString(2), constants.BITS, '0');
|
||||
};
|
||||
|
||||
module.exports = Address4;
|
971
node_modules/ip-address/lib/ipv6.js
generated
vendored
Normal file
971
node_modules/ip-address/lib/ipv6.js
generated
vendored
Normal file
@ -0,0 +1,971 @@
|
||||
'use strict';
|
||||
|
||||
var BigInteger = require('jsbn').BigInteger;
|
||||
var sprintf = require('sprintf-js').sprintf;
|
||||
|
||||
var merge = require('lodash.merge');
|
||||
var padStart = require('lodash.padstart');
|
||||
var repeat = require('lodash.repeat');
|
||||
var find = require('lodash.find');
|
||||
var max = require('lodash.max');
|
||||
|
||||
var constants4 = require('./v4/constants.js');
|
||||
var constants6 = require('./v6/constants.js');
|
||||
|
||||
var Address4 = require('./ipv4.js');
|
||||
|
||||
function addCommas(number) {
|
||||
var r = /(\d+)(\d{3})/;
|
||||
|
||||
while (r.test(number)) {
|
||||
number = number.replace(r, '$1,$2');
|
||||
}
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
function spanLeadingZeroes4(n) {
|
||||
n = n.replace(/^(0{1,})([1-9]+)$/, '<span class="parse-error">$1</span>$2');
|
||||
n = n.replace(/^(0{1,})(0)$/, '<span class="parse-error">$1</span>$2');
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an IPv6 address
|
||||
* @class Address6
|
||||
* @param {string} address - An IPv6 address string
|
||||
* @param {number} [groups=8] - How many octets to parse
|
||||
* @example
|
||||
* var address = new Address6('2001::/32');
|
||||
*/
|
||||
function Address6(address, optionalGroups) {
|
||||
if (optionalGroups === undefined) {
|
||||
this.groups = constants6.GROUPS;
|
||||
} else {
|
||||
this.groups = optionalGroups;
|
||||
}
|
||||
|
||||
this.v4 = false;
|
||||
|
||||
this.subnet = '/128';
|
||||
this.subnetMask = 128;
|
||||
|
||||
this.zone = '';
|
||||
|
||||
this.address = address;
|
||||
|
||||
var subnet = constants6.RE_SUBNET_STRING.exec(address);
|
||||
|
||||
if (subnet) {
|
||||
this.parsedSubnet = subnet[0].replace('/', '');
|
||||
this.subnetMask = parseInt(this.parsedSubnet, 10);
|
||||
this.subnet = '/' + this.subnetMask;
|
||||
|
||||
if (isNaN(this.subnetMask) ||
|
||||
this.subnetMask < 0 ||
|
||||
this.subnetMask > constants6.BITS) {
|
||||
this.valid = false;
|
||||
this.error = 'Invalid subnet mask.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
address = address.replace(constants6.RE_SUBNET_STRING, '');
|
||||
} else if (/\//.test(address)) {
|
||||
this.valid = false;
|
||||
this.error = 'Invalid subnet mask.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var zone = constants6.RE_ZONE_STRING.exec(address);
|
||||
|
||||
if (zone) {
|
||||
this.zone = zone[0];
|
||||
|
||||
address = address.replace(constants6.RE_ZONE_STRING, '');
|
||||
}
|
||||
|
||||
this.addressMinusSuffix = address;
|
||||
|
||||
this.parsedAddress = this.parse(this.addressMinusSuffix);
|
||||
}
|
||||
|
||||
merge(Address6.prototype, require('./v6/attributes.js'));
|
||||
merge(Address6.prototype, require('./v6/html.js'));
|
||||
merge(Address6.prototype, require('./v6/regular-expressions.js'));
|
||||
|
||||
/**
|
||||
* Convert a BigInteger to a v6 address object
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @param {BigInteger} bigInteger - a BigInteger to convert
|
||||
* @returns {Address6}
|
||||
* @example
|
||||
* var bigInteger = new BigInteger('1000000000000');
|
||||
* var address = Address6.fromBigInteger(bigInteger);
|
||||
* address.correctForm(); // '::e8:d4a5:1000'
|
||||
*/
|
||||
Address6.fromBigInteger = function (bigInteger) {
|
||||
var hex = padStart(bigInteger.toString(16), 32, '0');
|
||||
var groups = [];
|
||||
var i;
|
||||
|
||||
for (i = 0; i < constants6.GROUPS; i++) {
|
||||
groups.push(hex.slice(i * 4, (i + 1) * 4));
|
||||
}
|
||||
|
||||
return new Address6(groups.join(':'));
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a URL (with optional port number) to an address object
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @param {string} url - a URL with optional port number
|
||||
* @returns {Address6}
|
||||
* @example
|
||||
* var addressAndPort = Address6.fromURL('http://[ffff::]:8080/foo/');
|
||||
* addressAndPort.address.correctForm(); // 'ffff::'
|
||||
* addressAndPort.port; // 8080
|
||||
*/
|
||||
Address6.fromURL = function (url) {
|
||||
var host;
|
||||
var port;
|
||||
var result;
|
||||
|
||||
// If we have brackets parse them and find a port
|
||||
if (url.indexOf('[') !== -1 && url.indexOf(']:') !== -1) {
|
||||
result = constants6.RE_URL_WITH_PORT.exec(url);
|
||||
|
||||
if (result === null) {
|
||||
return {
|
||||
error: 'failed to parse address with port',
|
||||
address: null,
|
||||
port: null
|
||||
};
|
||||
}
|
||||
|
||||
host = result[1];
|
||||
port = result[2];
|
||||
// If there's a URL extract the address
|
||||
} else if (url.indexOf('/') !== -1) {
|
||||
// Remove the protocol prefix
|
||||
url = url.replace(/^[a-z0-9]+:\/\//, '');
|
||||
|
||||
// Parse the address
|
||||
result = constants6.RE_URL.exec(url);
|
||||
|
||||
if (result === null) {
|
||||
return {
|
||||
error: 'failed to parse address from URL',
|
||||
address: null,
|
||||
port: null
|
||||
};
|
||||
}
|
||||
|
||||
host = result[1];
|
||||
// Otherwise just assign the URL to the host and let the library parse it
|
||||
} else {
|
||||
host = url;
|
||||
}
|
||||
|
||||
// If there's a port convert it to an integer
|
||||
if (port) {
|
||||
port = parseInt(port, 10);
|
||||
|
||||
//squelch out of range ports
|
||||
if (port < 0 || port > 65536) {
|
||||
port = null;
|
||||
}
|
||||
} else {
|
||||
// Standardize `undefined` to `null`
|
||||
port = null;
|
||||
}
|
||||
|
||||
return {
|
||||
address: new Address6(host),
|
||||
port: port
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Create an IPv6-mapped address given an IPv4 address
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @param {string} address - An IPv4 address string
|
||||
* @returns {Address6}
|
||||
* @example
|
||||
* var address = Address6.fromAddress4('192.168.0.1');
|
||||
* address.correctForm(); // '::ffff:c0a8:1'
|
||||
* address.to4in6(); // '::ffff:192.168.0.1'
|
||||
*/
|
||||
Address6.fromAddress4 = function (address4) {
|
||||
var address4 = new Address4(address4);
|
||||
|
||||
var mask6 = constants6.BITS - (constants4.BITS - address4.subnetMask);
|
||||
|
||||
return new Address6('::ffff:' + address4.correctForm() + '/' + mask6);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return an address from ip6.arpa form
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @param {string} arpaFormAddress - an 'ip6.arpa' form address
|
||||
* @returns {Adress6}
|
||||
* @example
|
||||
* var address = Address6.fromArpa(e.f.f.f.3.c.2.6.f.f.f.e.6.6.8.e.1.0.6.7.9.4.e.c.0.0.0.0.1.0.0.2.ip6.arpa.)
|
||||
* address.correctForm(); // '2001:0:ce49:7601:e866:efff:62c3:fffe'
|
||||
*/
|
||||
Address6.fromArpa = function (arpaFormAddress) {
|
||||
//remove ending ".ip6.arpa." or just "."
|
||||
var address = arpaFormAddress.replace(/(\.ip6\.arpa)?\.$/, '');
|
||||
var semicolonAmount = 7;
|
||||
|
||||
//correct ip6.arpa form with ending removed will be 63 characters
|
||||
if (address.length !== 63) {
|
||||
address = {
|
||||
error: "Not Valid 'ip6.arpa' form",
|
||||
address: null
|
||||
};
|
||||
return address;
|
||||
}
|
||||
|
||||
address = address.split('.').reverse();
|
||||
|
||||
for (var i = semicolonAmount; i > 0; i--) {
|
||||
var insertIndex = i * 4;
|
||||
address.splice(insertIndex, 0, ':');
|
||||
}
|
||||
|
||||
address = address.join('');
|
||||
return new Address6(address);
|
||||
};
|
||||
|
||||
/*
|
||||
* A helper function to compact an array
|
||||
*/
|
||||
function compact (address, slice) {
|
||||
var s1 = [];
|
||||
var s2 = [];
|
||||
var i;
|
||||
|
||||
for (i = 0; i < address.length; i++) {
|
||||
if (i < slice[0]) {
|
||||
s1.push(address[i]);
|
||||
} else if (i > slice[1]) {
|
||||
s2.push(address[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return s1.concat(['compact']).concat(s2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Microsoft UNC transcription of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String} the Microsoft UNC transcription of the address
|
||||
*/
|
||||
Address6.prototype.microsoftTranscription = function () {
|
||||
return sprintf('%s.ipv6-literal.net',
|
||||
this.correctForm().replace(/:/g, '-'));
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the first n bits of the address, defaulting to the subnet mask
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @param {number} [mask=subnet] - the number of bits to mask
|
||||
* @returns {String} the first n bits of the address as a string
|
||||
*/
|
||||
Address6.prototype.mask = function (optionalMask) {
|
||||
if (optionalMask === undefined) {
|
||||
optionalMask = this.subnetMask;
|
||||
}
|
||||
|
||||
return this.getBitsBase2(0, optionalMask);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the number of possible subnets of a given size in the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @param {number} [size=128] - the subnet size
|
||||
* @returns {String}
|
||||
*/
|
||||
// TODO: probably useful to have a numeric version of this too
|
||||
Address6.prototype.possibleSubnets = function (optionalSubnetSize) {
|
||||
if (optionalSubnetSize === undefined) {
|
||||
optionalSubnetSize = 128;
|
||||
}
|
||||
|
||||
var availableBits = constants6.BITS - this.subnetMask;
|
||||
var subnetBits = Math.abs(optionalSubnetSize - constants6.BITS);
|
||||
var subnetPowers = availableBits - subnetBits;
|
||||
|
||||
if (subnetPowers < 0) {
|
||||
return '0';
|
||||
}
|
||||
|
||||
return addCommas(new BigInteger('2', 10).pow(subnetPowers).toString(10));
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function getting start address.
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {BigInteger}
|
||||
*/
|
||||
Address6.prototype._startAddress = function () {
|
||||
return new BigInteger(
|
||||
this.mask() + repeat('0', constants6.BITS - this.subnetMask), 2
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* The first address in the range given by this address' subnet
|
||||
* Often referred to as the Network Address.
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address6}
|
||||
*/
|
||||
Address6.prototype.startAddress = function () {
|
||||
return Address6.fromBigInteger(this._startAddress());
|
||||
};
|
||||
|
||||
/**
|
||||
* The first host address in the range given by this address's subnet ie
|
||||
* the first address after the Network Address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address6}
|
||||
*/
|
||||
Address6.prototype.startAddressExclusive = function () {
|
||||
var adjust = new BigInteger('1');
|
||||
return Address6.fromBigInteger(this._startAddress().add(adjust));
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function getting end address.
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {BigInteger}
|
||||
*/
|
||||
Address6.prototype._endAddress = function () {
|
||||
return new BigInteger(
|
||||
this.mask() + repeat('1', constants6.BITS - this.subnetMask), 2
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* The last address in the range given by this address' subnet
|
||||
* Often referred to as the Broadcast
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address6}
|
||||
*/
|
||||
Address6.prototype.endAddress = function () {
|
||||
return Address6.fromBigInteger(this._endAddress());
|
||||
};
|
||||
|
||||
/**
|
||||
* The last host address in the range given by this address's subnet ie
|
||||
* the last address prior to the Broadcast Address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address6}
|
||||
*/
|
||||
Address6.prototype.endAddressExclusive = function () {
|
||||
var adjust = new BigInteger('1');
|
||||
return Address6.fromBigInteger(this._endAddress().subtract(adjust));
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the scope of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
Address6.prototype.getScope = function () {
|
||||
var scope = constants6.SCOPES[this.getBits(12, 16)];
|
||||
|
||||
if (this.getType() === 'Global unicast' &&
|
||||
scope !== 'Link local') {
|
||||
scope = 'Global';
|
||||
}
|
||||
|
||||
return scope;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the type of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
Address6.prototype.getType = function () {
|
||||
var self = this;
|
||||
|
||||
function isType(name, type) {
|
||||
return self.isInSubnet(new Address6(type));
|
||||
}
|
||||
|
||||
return find(constants6.TYPES, isType) || 'Global unicast';
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the bits in the given range as a BigInteger
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {BigInteger}
|
||||
*/
|
||||
Address6.prototype.getBits = function (start, end) {
|
||||
return new BigInteger(this.getBitsBase2(start, end), 2);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the bits in the given range as a base-2 string
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
Address6.prototype.getBitsBase2 = function (start, end) {
|
||||
return this.binaryZeroPad().slice(start, end);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the bits in the given range as a base-16 string
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
Address6.prototype.getBitsBase16 = function (start, end) {
|
||||
var length = end - start;
|
||||
|
||||
if (length % 4 !== 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return padStart(this.getBits(start, end).toString(16), length / 4, '0');
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the bits that are set past the subnet mask length
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
Address6.prototype.getBitsPastSubnet = function () {
|
||||
return this.getBitsBase2(this.subnetMask, constants6.BITS);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the reversed ip6.arpa form of the address
|
||||
* @memberof Address6
|
||||
* @param {Object} options
|
||||
* @param {boolean} options.omitSuffix - omit the "ip6.arpa" suffix
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
Address6.prototype.reverseForm = function (options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
var characters = Math.floor(this.subnetMask / 4);
|
||||
|
||||
var reversed = this.canonicalForm()
|
||||
.replace(/:/g, '')
|
||||
.split('')
|
||||
.slice(0, characters)
|
||||
.reverse()
|
||||
.join('.');
|
||||
|
||||
if (characters > 0) {
|
||||
if (options.omitSuffix) {
|
||||
return reversed;
|
||||
}
|
||||
|
||||
return sprintf('%s.ip6.arpa.', reversed);
|
||||
}
|
||||
|
||||
if (options.omitSuffix) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return 'ip6.arpa.';
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the correct form of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
Address6.prototype.correctForm = function () {
|
||||
if (!this.parsedAddress) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var i;
|
||||
var groups = [];
|
||||
|
||||
var zeroCounter = 0;
|
||||
var zeroes = [];
|
||||
|
||||
for (i = 0; i < this.parsedAddress.length; i++) {
|
||||
var value = parseInt(this.parsedAddress[i], 16);
|
||||
|
||||
if (value === 0) {
|
||||
zeroCounter++;
|
||||
}
|
||||
|
||||
if (value !== 0 && zeroCounter > 0) {
|
||||
if (zeroCounter > 1) {
|
||||
zeroes.push([i - zeroCounter, i - 1]);
|
||||
}
|
||||
|
||||
zeroCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Do we end with a string of zeroes?
|
||||
if (zeroCounter > 1) {
|
||||
zeroes.push([this.parsedAddress.length - zeroCounter,
|
||||
this.parsedAddress.length - 1]);
|
||||
}
|
||||
|
||||
var zeroLengths = zeroes.map(function (n) {
|
||||
return (n[1] - n[0]) + 1;
|
||||
});
|
||||
|
||||
if (zeroes.length > 0) {
|
||||
var index = zeroLengths.indexOf(max(zeroLengths));
|
||||
|
||||
groups = compact(this.parsedAddress, zeroes[index]);
|
||||
} else {
|
||||
groups = this.parsedAddress;
|
||||
}
|
||||
|
||||
for (i = 0; i < groups.length; i++) {
|
||||
if (groups[i] !== 'compact') {
|
||||
groups[i] = parseInt(groups[i], 16).toString(16);
|
||||
}
|
||||
}
|
||||
|
||||
var correct = groups.join(':');
|
||||
|
||||
correct = correct.replace(/^compact$/, '::');
|
||||
correct = correct.replace(/^compact|compact$/, ':');
|
||||
correct = correct.replace(/compact/, '');
|
||||
|
||||
return correct;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a zero-padded base-2 string representation of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
* @example
|
||||
* var address = new Address6('2001:4860:4001:803::1011');
|
||||
* address.binaryZeroPad();
|
||||
* // '0010000000000001010010000110000001000000000000010000100000000011
|
||||
* // 0000000000000000000000000000000000000000000000000001000000010001'
|
||||
*/
|
||||
Address6.prototype.binaryZeroPad = function () {
|
||||
return padStart(this.bigInteger().toString(2), constants6.BITS, '0');
|
||||
};
|
||||
|
||||
// TODO: Improve the semantics of this helper function
|
||||
Address6.prototype.parse4in6 = function (address) {
|
||||
var groups = address.split(':');
|
||||
var lastGroup = groups.slice(-1)[0];
|
||||
|
||||
var address4 = lastGroup.match(constants4.RE_ADDRESS);
|
||||
|
||||
if (address4) {
|
||||
var temp4 = new Address4(address4[0]);
|
||||
|
||||
for (var i = 0; i < temp4.groups; i++) {
|
||||
if (/^0[0-9]+/.test(temp4.parsedAddress[i])) {
|
||||
this.valid = false;
|
||||
this.error = 'IPv4 addresses can not have leading zeroes.';
|
||||
|
||||
this.parseError = address.replace(constants4.RE_ADDRESS,
|
||||
temp4.parsedAddress.map(spanLeadingZeroes4).join('.'));
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
this.v4 = true;
|
||||
|
||||
groups[groups.length - 1] = temp4.toGroup6();
|
||||
|
||||
address = groups.join(':');
|
||||
}
|
||||
|
||||
return address;
|
||||
};
|
||||
|
||||
// TODO: Make private?
|
||||
Address6.prototype.parse = function (address) {
|
||||
address = this.parse4in6(address);
|
||||
|
||||
if (this.error) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var badCharacters = address.match(constants6.RE_BAD_CHARACTERS);
|
||||
|
||||
if (badCharacters) {
|
||||
this.valid = false;
|
||||
this.error = sprintf('Bad character%s detected in address: %s',
|
||||
badCharacters.length > 1 ? 's' : '', badCharacters.join(''));
|
||||
|
||||
this.parseError = address.replace(constants6.RE_BAD_CHARACTERS,
|
||||
'<span class="parse-error">$1</span>');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
var badAddress = address.match(constants6.RE_BAD_ADDRESS);
|
||||
|
||||
if (badAddress) {
|
||||
this.valid = false;
|
||||
this.error = sprintf('Address failed regex: %s', badAddress.join(''));
|
||||
|
||||
this.parseError = address.replace(constants6.RE_BAD_ADDRESS,
|
||||
'<span class="parse-error">$1</span>');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
var groups = [];
|
||||
|
||||
var halves = address.split('::');
|
||||
|
||||
if (halves.length === 2) {
|
||||
var first = halves[0].split(':');
|
||||
var last = halves[1].split(':');
|
||||
|
||||
if (first.length === 1 &&
|
||||
first[0] === '') {
|
||||
first = [];
|
||||
}
|
||||
|
||||
if (last.length === 1 &&
|
||||
last[0] === '') {
|
||||
last = [];
|
||||
}
|
||||
|
||||
var remaining = this.groups - (first.length + last.length);
|
||||
|
||||
if (!remaining) {
|
||||
this.valid = false;
|
||||
this.error = 'Error parsing groups';
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
this.elidedGroups = remaining;
|
||||
|
||||
this.elisionBegin = first.length;
|
||||
this.elisionEnd = first.length + this.elidedGroups;
|
||||
|
||||
first.forEach(function (group) {
|
||||
groups.push(group);
|
||||
});
|
||||
|
||||
for (var i = 0; i < remaining; i++) {
|
||||
groups.push(0);
|
||||
}
|
||||
|
||||
last.forEach(function (group) {
|
||||
groups.push(group);
|
||||
});
|
||||
} else if (halves.length === 1) {
|
||||
groups = address.split(':');
|
||||
|
||||
this.elidedGroups = 0;
|
||||
} else {
|
||||
this.valid = false;
|
||||
this.error = 'Too many :: groups found';
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
groups = groups.map(function (g) {
|
||||
return sprintf('%x', parseInt(g, 16));
|
||||
});
|
||||
|
||||
if (groups.length !== this.groups) {
|
||||
this.valid = false;
|
||||
this.error = 'Incorrect number of groups found';
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
this.valid = true;
|
||||
|
||||
return groups;
|
||||
};
|
||||
|
||||
function paddedHex(octet) {
|
||||
return sprintf('%04x', parseInt(octet, 16));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the canonical form of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
Address6.prototype.canonicalForm = function () {
|
||||
if (!this.valid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.parsedAddress.map(paddedHex).join(':');
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the decimal form of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
Address6.prototype.decimal = function () {
|
||||
if (!this.valid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.parsedAddress.map(function (n) {
|
||||
return sprintf('%05d', parseInt(n, 16));
|
||||
}).join(':');
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the address as a BigInteger
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {BigInteger}
|
||||
*/
|
||||
Address6.prototype.bigInteger = function () {
|
||||
if (!this.valid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BigInteger(this.parsedAddress.map(paddedHex).join(''), 16);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the last two groups of this address as an IPv4 address string
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address4}
|
||||
* @example
|
||||
* var address = new Address6('2001:4860:4001::1825:bf11');
|
||||
* address.to4().correctForm(); // '24.37.191.17'
|
||||
*/
|
||||
Address6.prototype.to4 = function () {
|
||||
var binary = this.binaryZeroPad().split('');
|
||||
|
||||
return Address4.fromHex(new BigInteger(binary.slice(96, 128)
|
||||
.join(''), 2).toString(16));
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the v4-in-v6 form of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
Address6.prototype.to4in6 = function () {
|
||||
var address4 = this.to4();
|
||||
var address6 = new Address6(this.parsedAddress.slice(0, 6).join(':'), 6);
|
||||
|
||||
var correct = address6.correctForm();
|
||||
|
||||
var infix = '';
|
||||
|
||||
if (!/:$/.test(correct)) {
|
||||
infix = ':';
|
||||
}
|
||||
|
||||
return address6.correctForm() + infix + address4.address;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return an object containing the Teredo properties of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Object}
|
||||
*/
|
||||
Address6.prototype.inspectTeredo = function () {
|
||||
/*
|
||||
- Bits 0 to 31 are set to the Teredo prefix (normally 2001:0000::/32).
|
||||
- Bits 32 to 63 embed the primary IPv4 address of the Teredo server that
|
||||
is used.
|
||||
- Bits 64 to 79 can be used to define some flags. Currently only the
|
||||
higher order bit is used; it is set to 1 if the Teredo client is
|
||||
located behind a cone NAT, 0 otherwise. For Microsoft's Windows Vista
|
||||
and Windows Server 2008 implementations, more bits are used. In those
|
||||
implementations, the format for these 16 bits is "CRAAAAUG AAAAAAAA",
|
||||
where "C" remains the "Cone" flag. The "R" bit is reserved for future
|
||||
use. The "U" bit is for the Universal/Local flag (set to 0). The "G" bit
|
||||
is Individual/Group flag (set to 0). The A bits are set to a 12-bit
|
||||
randomly generated number chosen by the Teredo client to introduce
|
||||
additional protection for the Teredo node against IPv6-based scanning
|
||||
attacks.
|
||||
- Bits 80 to 95 contains the obfuscated UDP port number. This is the
|
||||
port number that is mapped by the NAT to the Teredo client with all
|
||||
bits inverted.
|
||||
- Bits 96 to 127 contains the obfuscated IPv4 address. This is the
|
||||
public IPv4 address of the NAT with all bits inverted.
|
||||
*/
|
||||
var prefix = this.getBitsBase16(0, 32);
|
||||
|
||||
var udpPort = this.getBits(80, 96).xor(new BigInteger('ffff', 16)).toString();
|
||||
|
||||
var server4 = Address4.fromHex(this.getBitsBase16(32, 64));
|
||||
var client4 = Address4.fromHex(this.getBits(96, 128)
|
||||
.xor(new BigInteger('ffffffff', 16)).toString(16));
|
||||
|
||||
var flags = this.getBits(64, 80);
|
||||
var flagsBase2 = this.getBitsBase2(64, 80);
|
||||
|
||||
var coneNat = flags.testBit(15);
|
||||
var reserved = flags.testBit(14);
|
||||
var groupIndividual = flags.testBit(8);
|
||||
var universalLocal = flags.testBit(9);
|
||||
var nonce = new BigInteger(flagsBase2.slice(2, 6) +
|
||||
flagsBase2.slice(8, 16), 2).toString(10);
|
||||
|
||||
return {
|
||||
prefix: sprintf('%s:%s', prefix.slice(0, 4), prefix.slice(4, 8)),
|
||||
server4: server4.address,
|
||||
client4: client4.address,
|
||||
flags: flagsBase2,
|
||||
coneNat: coneNat,
|
||||
microsoft: {
|
||||
reserved: reserved,
|
||||
universalLocal: universalLocal,
|
||||
groupIndividual: groupIndividual,
|
||||
nonce: nonce
|
||||
},
|
||||
udpPort: udpPort
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Return an object containing the 6to4 properties of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Object}
|
||||
*/
|
||||
Address6.prototype.inspect6to4 = function () {
|
||||
/*
|
||||
- Bits 0 to 15 are set to the 6to4 prefix (2002::/16).
|
||||
- Bits 16 to 48 embed the IPv4 address of the 6to4 gateway that is used.
|
||||
*/
|
||||
|
||||
var prefix = this.getBitsBase16(0, 16);
|
||||
|
||||
var gateway = Address4.fromHex(this.getBitsBase16(16, 48));
|
||||
|
||||
return {
|
||||
prefix: sprintf('%s', prefix.slice(0, 4)),
|
||||
gateway: gateway.address
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a v6 6to4 address from a v6 v4inv6 address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address6}
|
||||
*/
|
||||
Address6.prototype.to6to4 = function () {
|
||||
if (!this.is4()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var addr6to4 = [
|
||||
'2002',
|
||||
this.getBitsBase16(96, 112),
|
||||
this.getBitsBase16(112, 128),
|
||||
'',
|
||||
'/16'
|
||||
].join(':');
|
||||
|
||||
return new Address6(addr6to4);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a byte array
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Array}
|
||||
*/
|
||||
Address6.prototype.toByteArray = function () {
|
||||
var byteArray = this.bigInteger().toByteArray();
|
||||
|
||||
// work around issue where `toByteArray` returns a leading 0 element
|
||||
if (byteArray.length === 17 && byteArray[0] === 0) {
|
||||
return byteArray.slice(1);
|
||||
}
|
||||
|
||||
return byteArray;
|
||||
};
|
||||
|
||||
function unsignByte(b) {
|
||||
return b & 0xFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an unsigned byte array
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Array}
|
||||
*/
|
||||
Address6.prototype.toUnsignedByteArray = function () {
|
||||
return this.toByteArray().map(unsignByte);
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a byte array to an Address6 object
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @returns {Address6}
|
||||
*/
|
||||
Address6.fromByteArray = function (bytes) {
|
||||
return this.fromUnsignedByteArray(bytes.map(unsignByte));
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert an unsigned byte array to an Address6 object
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @returns {Address6}
|
||||
*/
|
||||
Address6.fromUnsignedByteArray = function (bytes) {
|
||||
var BYTE_MAX = new BigInteger('256', 10);
|
||||
var result = new BigInteger('0', 10);
|
||||
var multiplier = new BigInteger('1', 10);
|
||||
|
||||
for (var i = bytes.length - 1; i >= 0; i--) {
|
||||
result = result.add(
|
||||
multiplier.multiply(new BigInteger(bytes[i].toString(10), 10)));
|
||||
|
||||
multiplier = multiplier.multiply(BYTE_MAX);
|
||||
}
|
||||
|
||||
return Address6.fromBigInteger(result);
|
||||
};
|
||||
|
||||
module.exports = Address6;
|
6
node_modules/ip-address/lib/v4/constants.js
generated
vendored
Normal file
6
node_modules/ip-address/lib/v4/constants.js
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
exports.BITS = 32;
|
||||
exports.GROUPS = 4;
|
||||
|
||||
exports.RE_ADDRESS = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/g;
|
||||
|
||||
exports.RE_SUBNET_STRING = /\/\d{1,2}$/;
|
106
node_modules/ip-address/lib/v6/attributes.js
generated
vendored
Normal file
106
node_modules/ip-address/lib/v6/attributes.js
generated
vendored
Normal file
@ -0,0 +1,106 @@
|
||||
'use strict';
|
||||
|
||||
var common = require('../common.js');
|
||||
var v6 = require('./constants.js');
|
||||
|
||||
/**
|
||||
* Returns true if the address is valid, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
exports.isValid = function () {
|
||||
return this.valid;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the given address is in the subnet of the current address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
exports.isInSubnet = common.isInSubnet;
|
||||
|
||||
/**
|
||||
* Returns true if the address is correct, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
exports.isCorrect = common.isCorrect(v6.BITS);
|
||||
|
||||
/**
|
||||
* Returns true if the address is in the canonical form, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
exports.isCanonical = common.falseIfInvalid(function () {
|
||||
return this.addressMinusSuffix === this.canonicalForm();
|
||||
});
|
||||
|
||||
/**
|
||||
* Returns true if the address is a link local address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
exports.isLinkLocal = common.falseIfInvalid(function () {
|
||||
// Zeroes are required, i.e. we can't check isInSubnet with 'fe80::/10'
|
||||
if (this.getBitsBase2(0, 64) ===
|
||||
'1111111010000000000000000000000000000000000000000000000000000000') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/**
|
||||
* Returns true if the address is a multicast address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
exports.isMulticast = common.falseIfInvalid(function () {
|
||||
return this.getType() === 'Multicast';
|
||||
});
|
||||
|
||||
/**
|
||||
* Returns true if the address is a v4-in-v6 address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
exports.is4 = common.falseIfInvalid(function () {
|
||||
return this.v4;
|
||||
});
|
||||
|
||||
/**
|
||||
* Returns true if the address is a Teredo address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
exports.isTeredo = common.falseIfInvalid(function () {
|
||||
return this.isInSubnet(new this.constructor('2001::/32'));
|
||||
});
|
||||
|
||||
/**
|
||||
* Returns true if the address is a 6to4 address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
exports.is6to4 = common.falseIfInvalid(function () {
|
||||
return this.isInSubnet(new this.constructor('2002::/16'));
|
||||
});
|
||||
|
||||
/**
|
||||
* Returns true if the address is a loopback address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
exports.isLoopback = common.falseIfInvalid(function () {
|
||||
return this.getType() === 'Loopback';
|
||||
});
|
79
node_modules/ip-address/lib/v6/constants.js
generated
vendored
Normal file
79
node_modules/ip-address/lib/v6/constants.js
generated
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
exports.BITS = 128;
|
||||
exports.GROUPS = 8;
|
||||
|
||||
/**
|
||||
* Represents IPv6 address scopes
|
||||
* @memberof Address6
|
||||
* @static
|
||||
*/
|
||||
exports.SCOPES = {
|
||||
0: 'Reserved',
|
||||
1: 'Interface local',
|
||||
2: 'Link local',
|
||||
4: 'Admin local',
|
||||
5: 'Site local',
|
||||
8: 'Organization local',
|
||||
14: 'Global',
|
||||
15: 'Reserved'
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents IPv6 address types
|
||||
* @memberof Address6
|
||||
* @static
|
||||
*/
|
||||
exports.TYPES = {
|
||||
'ff01::1/128': 'Multicast (All nodes on this interface)',
|
||||
'ff01::2/128': 'Multicast (All routers on this interface)',
|
||||
'ff02::1/128': 'Multicast (All nodes on this link)',
|
||||
'ff02::2/128': 'Multicast (All routers on this link)',
|
||||
'ff05::2/128': 'Multicast (All routers in this site)',
|
||||
'ff02::5/128': 'Multicast (OSPFv3 AllSPF routers)',
|
||||
'ff02::6/128': 'Multicast (OSPFv3 AllDR routers)',
|
||||
'ff02::9/128': 'Multicast (RIP routers)',
|
||||
'ff02::a/128': 'Multicast (EIGRP routers)',
|
||||
'ff02::d/128': 'Multicast (PIM routers)',
|
||||
'ff02::16/128': 'Multicast (MLDv2 reports)',
|
||||
'ff01::fb/128': 'Multicast (mDNSv6)',
|
||||
'ff02::fb/128': 'Multicast (mDNSv6)',
|
||||
'ff05::fb/128': 'Multicast (mDNSv6)',
|
||||
'ff02::1:2/128': 'Multicast (All DHCP servers and relay agents on this link)',
|
||||
'ff05::1:2/128': 'Multicast (All DHCP servers and relay agents in this site)',
|
||||
'ff02::1:3/128': 'Multicast (All DHCP servers on this link)',
|
||||
'ff05::1:3/128': 'Multicast (All DHCP servers in this site)',
|
||||
'::/128': 'Unspecified',
|
||||
'::1/128': 'Loopback',
|
||||
'ff00::/8': 'Multicast',
|
||||
'fe80::/10': 'Link-local unicast'
|
||||
};
|
||||
|
||||
/**
|
||||
* A regular expression that matches bad characters in an IPv6 address
|
||||
* @memberof Address6
|
||||
* @static
|
||||
*/
|
||||
exports.RE_BAD_CHARACTERS = /([^0-9a-f:\/%])/ig;
|
||||
|
||||
/**
|
||||
* A regular expression that matches an incorrect IPv6 address
|
||||
* @memberof Address6
|
||||
* @static
|
||||
*/
|
||||
exports.RE_BAD_ADDRESS = /([0-9a-f]{5,}|:{3,}|[^:]:$|^:[^:]|\/$)/ig;
|
||||
|
||||
/**
|
||||
* A regular expression that matches an IPv6 subnet
|
||||
* @memberof Address6
|
||||
* @static
|
||||
*/
|
||||
exports.RE_SUBNET_STRING = /\/\d{1,3}(?=%|$)/;
|
||||
|
||||
/**
|
||||
* A regular expression that matches an IPv6 zone
|
||||
* @memberof Address6
|
||||
* @static
|
||||
*/
|
||||
exports.RE_ZONE_STRING = /%.*$/;
|
||||
|
||||
exports.RE_URL = new RegExp(/^\[{0,1}([0-9a-f:]+)\]{0,1}/);
|
||||
exports.RE_URL_WITH_PORT = new RegExp(/\[([0-9a-f:]+)\]:([0-9]{1,5})/);
|
64
node_modules/ip-address/lib/v6/helpers.js
generated
vendored
Normal file
64
node_modules/ip-address/lib/v6/helpers.js
generated
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
'use strict';
|
||||
|
||||
var sprintf = require('sprintf-js').sprintf;
|
||||
|
||||
/**
|
||||
* @returns {String} the string with all zeroes contained in a <span>
|
||||
*/
|
||||
var spanAllZeroes = exports.spanAllZeroes = function (s) {
|
||||
return s.replace(/(0+)/g, '<span class="zero">$1</span>');
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {String} the string with each character contained in a <span>
|
||||
*/
|
||||
exports.spanAll = function (s, optionalOffset) {
|
||||
if (optionalOffset === undefined) {
|
||||
optionalOffset = 0;
|
||||
}
|
||||
|
||||
var letters = s.split('');
|
||||
|
||||
return letters.map(function (n, i) {
|
||||
return sprintf('<span class="digit value-%s position-%d">%s</span>', n,
|
||||
i + optionalOffset,
|
||||
spanAllZeroes(n)); // XXX Use #base-2 .value-0 instead?
|
||||
}).join('');
|
||||
};
|
||||
|
||||
function spanLeadingZeroesSimple(group) {
|
||||
return group.replace(/^(0+)/, '<span class="zero">$1</span>');
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {String} the string with leading zeroes contained in a <span>
|
||||
*/
|
||||
exports.spanLeadingZeroes = function (address) {
|
||||
var groups = address.split(':');
|
||||
|
||||
return groups.map(function (g) {
|
||||
return spanLeadingZeroesSimple(g);
|
||||
}).join(':');
|
||||
};
|
||||
|
||||
/**
|
||||
* Groups an address
|
||||
* @returns {String} a grouped address
|
||||
*/
|
||||
exports.simpleGroup = function (addressString, offset) {
|
||||
var groups = addressString.split(':');
|
||||
|
||||
if (!offset) {
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
return groups.map(function (g, i) {
|
||||
if (/group-v4/.test(g)) {
|
||||
return g;
|
||||
}
|
||||
|
||||
return sprintf('<span class="hover-group group-%d">%s</span>',
|
||||
i + offset,
|
||||
spanLeadingZeroesSimple(g));
|
||||
}).join(':');
|
||||
};
|
107
node_modules/ip-address/lib/v6/html.js
generated
vendored
Normal file
107
node_modules/ip-address/lib/v6/html.js
generated
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
'use strict';
|
||||
|
||||
var constants4 = require('../v4/constants.js');
|
||||
var helpers = require('./helpers.js');
|
||||
var sprintf = require('sprintf-js').sprintf;
|
||||
|
||||
/**
|
||||
* @returns {String} the address in link form with a default port of 80
|
||||
*/
|
||||
exports.href = function (optionalPort) {
|
||||
if (optionalPort === undefined) {
|
||||
optionalPort = '';
|
||||
} else {
|
||||
optionalPort = sprintf(':%s', optionalPort);
|
||||
}
|
||||
|
||||
return sprintf('http://[%s]%s/', this.correctForm(), optionalPort);
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {String} a link suitable for conveying the address via a URL hash
|
||||
*/
|
||||
exports.link = function (options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
if (options.className === undefined) {
|
||||
options.className = '';
|
||||
}
|
||||
|
||||
if (options.prefix === undefined) {
|
||||
options.prefix = '/#address=';
|
||||
}
|
||||
|
||||
if (options.v4 === undefined) {
|
||||
options.v4 = false;
|
||||
}
|
||||
|
||||
var formFunction = this.correctForm;
|
||||
|
||||
if (options.v4) {
|
||||
formFunction = this.to4in6;
|
||||
}
|
||||
|
||||
if (options.className) {
|
||||
return sprintf('<a href="%1$s%2$s" class="%3$s">%2$s</a>',
|
||||
options.prefix, formFunction.call(this), options.className);
|
||||
}
|
||||
|
||||
return sprintf('<a href="%1$s%2$s">%2$s</a>', options.prefix,
|
||||
formFunction.call(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Groups an address
|
||||
* @returns {String}
|
||||
*/
|
||||
exports.group = function () {
|
||||
var address4 = this.address.match(constants4.RE_ADDRESS);
|
||||
var i;
|
||||
|
||||
if (address4) {
|
||||
// The IPv4 case
|
||||
var segments = address4[0].split('.');
|
||||
|
||||
this.address = this.address.replace(constants4.RE_ADDRESS,
|
||||
sprintf('<span class="hover-group group-v4 group-6">%s</span>' +
|
||||
'.' +
|
||||
'<span class="hover-group group-v4 group-7">%s</span>',
|
||||
segments.slice(0, 2).join('.'),
|
||||
segments.slice(2, 4).join('.')));
|
||||
}
|
||||
|
||||
if (this.elidedGroups === 0) {
|
||||
// The simple case
|
||||
return helpers.simpleGroup(this.address);
|
||||
}
|
||||
|
||||
// The elided case
|
||||
var output = [];
|
||||
|
||||
var halves = this.address.split('::');
|
||||
|
||||
if (halves[0].length) {
|
||||
output.push(helpers.simpleGroup(halves[0]));
|
||||
} else {
|
||||
output.push('');
|
||||
}
|
||||
|
||||
var classes = ['hover-group'];
|
||||
|
||||
for (i = this.elisionBegin;
|
||||
i < this.elisionBegin + this.elidedGroups; i++) {
|
||||
classes.push(sprintf('group-%d', i));
|
||||
}
|
||||
|
||||
output.push(sprintf('<span class="%s"></span>', classes.join(' ')));
|
||||
|
||||
if (halves[1].length) {
|
||||
output.push(helpers.simpleGroup(halves[1], this.elisionEnd));
|
||||
} else {
|
||||
output.push('');
|
||||
}
|
||||
|
||||
return output.join(':');
|
||||
};
|
159
node_modules/ip-address/lib/v6/regular-expressions.js
generated
vendored
Normal file
159
node_modules/ip-address/lib/v6/regular-expressions.js
generated
vendored
Normal file
@ -0,0 +1,159 @@
|
||||
'use strict';
|
||||
|
||||
var sprintf = require('sprintf-js').sprintf;
|
||||
|
||||
var v6 = require('./constants.js');
|
||||
|
||||
function groupPossibilities(possibilities) {
|
||||
return sprintf('(%s)', possibilities.join('|'));
|
||||
}
|
||||
|
||||
function padGroup(group) {
|
||||
if (group.length < 4) {
|
||||
return sprintf('0{0,%d}%s', 4 - group.length, group);
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
var ADDRESS_BOUNDARY = '[^A-Fa-f0-9:]';
|
||||
|
||||
function simpleRegularExpression(groups) {
|
||||
var zeroIndexes = [];
|
||||
|
||||
groups.forEach(function (group, i) {
|
||||
var groupInteger = parseInt(group, 16);
|
||||
|
||||
if (groupInteger === 0) {
|
||||
zeroIndexes.push(i);
|
||||
}
|
||||
});
|
||||
|
||||
// You can technically elide a single 0, this creates the regular expressions
|
||||
// to match that eventuality
|
||||
var possibilities = zeroIndexes.map(function (zeroIndex) {
|
||||
return groups.map(function (group, i) {
|
||||
if (i === zeroIndex) {
|
||||
var elision = (i === 0 || i === v6.GROUPS - 1) ? ':' : '';
|
||||
|
||||
return groupPossibilities([padGroup(group), elision]);
|
||||
}
|
||||
|
||||
return padGroup(group);
|
||||
}).join(':');
|
||||
});
|
||||
|
||||
// The simplest case
|
||||
possibilities.push(groups.map(padGroup).join(':'));
|
||||
|
||||
return groupPossibilities(possibilities);
|
||||
}
|
||||
|
||||
function possibleElisions(elidedGroups, moreLeft, moreRight) {
|
||||
var left = moreLeft ? '' : ':';
|
||||
var right = moreRight ? '' : ':';
|
||||
|
||||
var possibilities = [];
|
||||
|
||||
// 1. elision of everything (::)
|
||||
if (!moreLeft && !moreRight) {
|
||||
possibilities.push('::');
|
||||
}
|
||||
|
||||
// 2. complete elision of the middle
|
||||
if (moreLeft && moreRight) {
|
||||
possibilities.push('');
|
||||
}
|
||||
|
||||
if ((moreRight && !moreLeft) || (!moreRight && moreLeft)) {
|
||||
// 3. complete elision of one side
|
||||
possibilities.push(':');
|
||||
}
|
||||
|
||||
// 4. elision from the left side
|
||||
possibilities.push(sprintf('%s(:0{1,4}){1,%d}', left, elidedGroups - 1));
|
||||
|
||||
// 5. elision from the right side
|
||||
possibilities.push(sprintf('(0{1,4}:){1,%d}%s', elidedGroups - 1, right));
|
||||
|
||||
// 6. no elision
|
||||
possibilities.push(sprintf('(0{1,4}:){%d}0{1,4}', elidedGroups - 1));
|
||||
|
||||
// 7. elision (including sloppy elision) from the middle
|
||||
for (var groups = 1; groups < elidedGroups - 1; groups++) {
|
||||
for (var position = 1; position < elidedGroups - groups; position++) {
|
||||
possibilities.push(sprintf('(0{1,4}:){%d}:(0{1,4}:){%d}0{1,4}',
|
||||
position,
|
||||
elidedGroups - position - groups - 1));
|
||||
}
|
||||
}
|
||||
|
||||
return groupPossibilities(possibilities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a regular expression string that can be used to find or validate
|
||||
* all variations of this address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @param {string} optionalSubString
|
||||
* @returns {string}
|
||||
*/
|
||||
exports.regularExpressionString = function (optionalSubString) {
|
||||
if (optionalSubString === undefined) {
|
||||
optionalSubString = false;
|
||||
}
|
||||
|
||||
var output = [];
|
||||
|
||||
// TODO: revisit why this is necessary
|
||||
var address6 = new this.constructor(this.correctForm());
|
||||
|
||||
if (address6.elidedGroups === 0) {
|
||||
// The simple case
|
||||
output.push(simpleRegularExpression(address6.parsedAddress));
|
||||
} else if (address6.elidedGroups === v6.GROUPS) {
|
||||
// A completely elided address
|
||||
output.push(possibleElisions(v6.GROUPS));
|
||||
} else {
|
||||
// A partially elided address
|
||||
var halves = address6.address.split('::');
|
||||
|
||||
if (halves[0].length) {
|
||||
output.push(simpleRegularExpression(halves[0].split(':')));
|
||||
}
|
||||
|
||||
output.push(possibleElisions(address6.elidedGroups,
|
||||
halves[0].length !== 0,
|
||||
halves[1].length !== 0));
|
||||
|
||||
if (halves[1].length) {
|
||||
output.push(simpleRegularExpression(halves[1].split(':')));
|
||||
}
|
||||
|
||||
output = [output.join(':')];
|
||||
}
|
||||
|
||||
if (!optionalSubString) {
|
||||
output = [].concat(
|
||||
'(?=^|',
|
||||
ADDRESS_BOUNDARY,
|
||||
'|[^\\w\\:])(', output, ')(?=[^\\w\\:]|',
|
||||
ADDRESS_BOUNDARY,
|
||||
'|$)');
|
||||
}
|
||||
|
||||
return output.join('');
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate a regular expression that can be used to find or validate all
|
||||
* variations of this address.
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @param {string} optionalSubString
|
||||
* @returns {RegExp}
|
||||
*/
|
||||
exports.regularExpression = function (optionalSubstring) {
|
||||
return new RegExp(this.regularExpressionString(optionalSubstring), 'i');
|
||||
};
|
50
node_modules/ip-address/package.json
generated
vendored
Normal file
50
node_modules/ip-address/package.json
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "ip-address",
|
||||
"description": "A library for parsing IPv4 and IPv6 IP addresses in node and the browser.",
|
||||
"keywords": [
|
||||
"ipv6",
|
||||
"ipv4",
|
||||
"browser",
|
||||
"validation"
|
||||
],
|
||||
"version": "6.4.0",
|
||||
"author": "Beau Gunderson <beau@beaugunderson.com> (https://beaugunderson.com/)",
|
||||
"license": "MIT",
|
||||
"main": "ip-address.js",
|
||||
"scripts": {
|
||||
"docs": "documentation build --github --output docs --format html ./ip-address.js",
|
||||
"release": "release-it",
|
||||
"test": "mocha -R spec"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
},
|
||||
"files": [
|
||||
"ip-address.js",
|
||||
"ip-address-globals.js",
|
||||
"lib/**/*"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/beaugunderson/ip-address.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"jsbn": "1.1.0",
|
||||
"lodash.find": "4.6.0",
|
||||
"lodash.max": "4.0.1",
|
||||
"lodash.merge": "4.6.2",
|
||||
"lodash.padstart": "4.6.1",
|
||||
"lodash.repeat": "4.1.0",
|
||||
"sprintf-js": "1.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "^16.5.2",
|
||||
"chai": "^4.2.0",
|
||||
"codecov.io": "^0.1.6",
|
||||
"documentation": "^13.0.2",
|
||||
"istanbul": "^0.4.5",
|
||||
"mocha": "^8.1.3",
|
||||
"mochify": "^6.6.0",
|
||||
"release-it": "^14.0.2"
|
||||
}
|
||||
}
|
46
node_modules/ip/.jscsrc
generated
vendored
Normal file
46
node_modules/ip/.jscsrc
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
{
|
||||
"disallowKeywordsOnNewLine": [ "else" ],
|
||||
"disallowMixedSpacesAndTabs": true,
|
||||
"disallowMultipleLineStrings": true,
|
||||
"disallowMultipleVarDecl": true,
|
||||
"disallowNewlineBeforeBlockStatements": true,
|
||||
"disallowQuotedKeysInObjects": true,
|
||||
"disallowSpaceAfterObjectKeys": true,
|
||||
"disallowSpaceAfterPrefixUnaryOperators": true,
|
||||
"disallowSpaceBeforePostfixUnaryOperators": true,
|
||||
"disallowSpacesInCallExpression": true,
|
||||
"disallowTrailingComma": true,
|
||||
"disallowTrailingWhitespace": true,
|
||||
"disallowYodaConditions": true,
|
||||
|
||||
"requireCommaBeforeLineBreak": true,
|
||||
"requireOperatorBeforeLineBreak": true,
|
||||
"requireSpaceAfterBinaryOperators": true,
|
||||
"requireSpaceAfterKeywords": [ "if", "for", "while", "else", "try", "catch" ],
|
||||
"requireSpaceAfterLineComment": true,
|
||||
"requireSpaceBeforeBinaryOperators": true,
|
||||
"requireSpaceBeforeBlockStatements": true,
|
||||
"requireSpaceBeforeKeywords": [ "else", "catch" ],
|
||||
"requireSpaceBeforeObjectValues": true,
|
||||
"requireSpaceBetweenArguments": true,
|
||||
"requireSpacesInAnonymousFunctionExpression": {
|
||||
"beforeOpeningCurlyBrace": true
|
||||
},
|
||||
"requireSpacesInFunctionDeclaration": {
|
||||
"beforeOpeningCurlyBrace": true
|
||||
},
|
||||
"requireSpacesInFunctionExpression": {
|
||||
"beforeOpeningCurlyBrace": true
|
||||
},
|
||||
"requireSpacesInConditionalExpression": true,
|
||||
"requireSpacesInForStatement": true,
|
||||
"requireSpacesInsideArrayBrackets": "all",
|
||||
"requireSpacesInsideObjectBrackets": "all",
|
||||
"requireDotNotation": true,
|
||||
|
||||
"maximumLineLength": 80,
|
||||
"validateIndentation": 2,
|
||||
"validateLineBreaks": "LF",
|
||||
"validateParameterSeparator": ", ",
|
||||
"validateQuoteMarks": "'"
|
||||
}
|
89
node_modules/ip/.jshintrc
generated
vendored
Normal file
89
node_modules/ip/.jshintrc
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
{
|
||||
// JSHint Default Configuration File (as on JSHint website)
|
||||
// See http://jshint.com/docs/ for more details
|
||||
|
||||
"maxerr" : 50, // {int} Maximum error before stopping
|
||||
|
||||
// Enforcing
|
||||
"bitwise" : false, // true: Prohibit bitwise operators (&, |, ^, etc.)
|
||||
"camelcase" : false, // true: Identifiers must be in camelCase
|
||||
"curly" : false, // true: Require {} for every new block or scope
|
||||
"eqeqeq" : true, // true: Require triple equals (===) for comparison
|
||||
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
|
||||
"freeze" : true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc.
|
||||
"immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
|
||||
"indent" : 2, // {int} Number of spaces to use for indentation
|
||||
"latedef" : true, // true: Require variables/functions to be defined before being used
|
||||
"newcap" : true, // true: Require capitalization of all constructor functions e.g. `new F()`
|
||||
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
|
||||
"noempty" : false, // true: Prohibit use of empty blocks
|
||||
"nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters.
|
||||
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
|
||||
"plusplus" : false, // true: Prohibit use of `++` & `--`
|
||||
"quotmark" : "single", // Quotation mark consistency:
|
||||
// false : do nothing (default)
|
||||
// true : ensure whatever is used is consistent
|
||||
// "single" : require single quotes
|
||||
// "double" : require double quotes
|
||||
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
|
||||
"unused" : true, // true: Require all defined variables be used
|
||||
"strict" : true, // true: Requires all functions run in ES5 Strict Mode
|
||||
"maxparams" : false, // {int} Max number of formal params allowed per function
|
||||
"maxdepth" : 3, // {int} Max depth of nested blocks (within functions)
|
||||
"maxstatements" : false, // {int} Max number statements per function
|
||||
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
|
||||
"maxlen" : false, // {int} Max number of characters per line
|
||||
|
||||
// Relaxing
|
||||
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
|
||||
"boss" : false, // true: Tolerate assignments where comparisons would be expected
|
||||
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
|
||||
"eqnull" : false, // true: Tolerate use of `== null`
|
||||
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
|
||||
"esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`)
|
||||
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
|
||||
// (ex: `for each`, multiple try/catch, function expression…)
|
||||
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
|
||||
"expr" : false, // true: Tolerate `ExpressionStatement` as Programs
|
||||
"funcscope" : false, // true: Tolerate defining variables inside control statements
|
||||
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
|
||||
"iterator" : false, // true: Tolerate using the `__iterator__` property
|
||||
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
|
||||
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings
|
||||
"laxcomma" : false, // true: Tolerate comma-first style coding
|
||||
"loopfunc" : false, // true: Tolerate functions being defined in loops
|
||||
"multistr" : false, // true: Tolerate multi-line strings
|
||||
"noyield" : false, // true: Tolerate generator functions with no yield statement in them.
|
||||
"notypeof" : false, // true: Tolerate invalid typeof operator values
|
||||
"proto" : false, // true: Tolerate using the `__proto__` property
|
||||
"scripturl" : false, // true: Tolerate script-targeted URLs
|
||||
"shadow" : true, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
|
||||
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
|
||||
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
|
||||
"validthis" : false, // true: Tolerate using this in a non-constructor function
|
||||
|
||||
// Environments
|
||||
"browser" : true, // Web Browser (window, document, etc)
|
||||
"browserify" : true, // Browserify (node.js code in the browser)
|
||||
"couch" : false, // CouchDB
|
||||
"devel" : true, // Development/debugging (alert, confirm, etc)
|
||||
"dojo" : false, // Dojo Toolkit
|
||||
"jasmine" : false, // Jasmine
|
||||
"jquery" : false, // jQuery
|
||||
"mocha" : true, // Mocha
|
||||
"mootools" : false, // MooTools
|
||||
"node" : true, // Node.js
|
||||
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
|
||||
"prototypejs" : false, // Prototype and Scriptaculous
|
||||
"qunit" : false, // QUnit
|
||||
"rhino" : false, // Rhino
|
||||
"shelljs" : false, // ShellJS
|
||||
"worker" : false, // Web Workers
|
||||
"wsh" : false, // Windows Scripting Host
|
||||
"yui" : false, // Yahoo User Interface
|
||||
|
||||
// Custom Globals
|
||||
"globals" : {
|
||||
"module": true
|
||||
} // additional predefined global variables
|
||||
}
|
2
node_modules/ip/.npmignore
generated
vendored
Normal file
2
node_modules/ip/.npmignore
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
npm-debug.log
|
15
node_modules/ip/.travis.yml
generated
vendored
Normal file
15
node_modules/ip/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.8"
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "4"
|
||||
- "6"
|
||||
|
||||
before_install:
|
||||
- travis_retry npm install -g npm@2.14.5
|
||||
- travis_retry npm install
|
||||
|
||||
script:
|
||||
- npm test
|
90
node_modules/ip/README.md
generated
vendored
Normal file
90
node_modules/ip/README.md
generated
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
# IP
|
||||
[](https://www.npmjs.com/package/ip)
|
||||
|
||||
IP address utilities for node.js
|
||||
|
||||
## Installation
|
||||
|
||||
### npm
|
||||
```shell
|
||||
npm install ip
|
||||
```
|
||||
|
||||
### git
|
||||
|
||||
```shell
|
||||
git clone https://github.com/indutny/node-ip.git
|
||||
```
|
||||
|
||||
## Usage
|
||||
Get your ip address, compare ip addresses, validate ip addresses, etc.
|
||||
|
||||
```js
|
||||
var ip = require('ip');
|
||||
|
||||
ip.address() // my ip address
|
||||
ip.isEqual('::1', '::0:1'); // true
|
||||
ip.toBuffer('127.0.0.1') // Buffer([127, 0, 0, 1])
|
||||
ip.toString(new Buffer([127, 0, 0, 1])) // 127.0.0.1
|
||||
ip.fromPrefixLen(24) // 255.255.255.0
|
||||
ip.mask('192.168.1.134', '255.255.255.0') // 192.168.1.0
|
||||
ip.cidr('192.168.1.134/26') // 192.168.1.128
|
||||
ip.not('255.255.255.0') // 0.0.0.255
|
||||
ip.or('192.168.1.134', '0.0.0.255') // 192.168.1.255
|
||||
ip.isPrivate('127.0.0.1') // true
|
||||
ip.isV4Format('127.0.0.1'); // true
|
||||
ip.isV6Format('::ffff:127.0.0.1'); // true
|
||||
|
||||
// operate on buffers in-place
|
||||
var buf = new Buffer(128);
|
||||
var offset = 64;
|
||||
ip.toBuffer('127.0.0.1', buf, offset); // [127, 0, 0, 1] at offset 64
|
||||
ip.toString(buf, offset, 4); // '127.0.0.1'
|
||||
|
||||
// subnet information
|
||||
ip.subnet('192.168.1.134', '255.255.255.192')
|
||||
// { networkAddress: '192.168.1.128',
|
||||
// firstAddress: '192.168.1.129',
|
||||
// lastAddress: '192.168.1.190',
|
||||
// broadcastAddress: '192.168.1.191',
|
||||
// subnetMask: '255.255.255.192',
|
||||
// subnetMaskLength: 26,
|
||||
// numHosts: 62,
|
||||
// length: 64,
|
||||
// contains: function(addr){...} }
|
||||
ip.cidrSubnet('192.168.1.134/26')
|
||||
// Same as previous.
|
||||
|
||||
// range checking
|
||||
ip.cidrSubnet('192.168.1.134/26').contains('192.168.1.190') // true
|
||||
|
||||
|
||||
// ipv4 long conversion
|
||||
ip.toLong('127.0.0.1'); // 2130706433
|
||||
ip.fromLong(2130706433); // '127.0.0.1'
|
||||
```
|
||||
|
||||
### License
|
||||
|
||||
This software is licensed under the MIT License.
|
||||
|
||||
Copyright Fedor Indutny, 2012.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
persons to whom the Software is furnished to do so, subject to the
|
||||
following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
416
node_modules/ip/lib/ip.js
generated
vendored
Normal file
416
node_modules/ip/lib/ip.js
generated
vendored
Normal file
@ -0,0 +1,416 @@
|
||||
'use strict';
|
||||
|
||||
var ip = exports;
|
||||
var Buffer = require('buffer').Buffer;
|
||||
var os = require('os');
|
||||
|
||||
ip.toBuffer = function(ip, buff, offset) {
|
||||
offset = ~~offset;
|
||||
|
||||
var result;
|
||||
|
||||
if (this.isV4Format(ip)) {
|
||||
result = buff || new Buffer(offset + 4);
|
||||
ip.split(/\./g).map(function(byte) {
|
||||
result[offset++] = parseInt(byte, 10) & 0xff;
|
||||
});
|
||||
} else if (this.isV6Format(ip)) {
|
||||
var sections = ip.split(':', 8);
|
||||
|
||||
var i;
|
||||
for (i = 0; i < sections.length; i++) {
|
||||
var isv4 = this.isV4Format(sections[i]);
|
||||
var v4Buffer;
|
||||
|
||||
if (isv4) {
|
||||
v4Buffer = this.toBuffer(sections[i]);
|
||||
sections[i] = v4Buffer.slice(0, 2).toString('hex');
|
||||
}
|
||||
|
||||
if (v4Buffer && ++i < 8) {
|
||||
sections.splice(i, 0, v4Buffer.slice(2, 4).toString('hex'));
|
||||
}
|
||||
}
|
||||
|
||||
if (sections[0] === '') {
|
||||
while (sections.length < 8) sections.unshift('0');
|
||||
} else if (sections[sections.length - 1] === '') {
|
||||
while (sections.length < 8) sections.push('0');
|
||||
} else if (sections.length < 8) {
|
||||
for (i = 0; i < sections.length && sections[i] !== ''; i++);
|
||||
var argv = [ i, 1 ];
|
||||
for (i = 9 - sections.length; i > 0; i--) {
|
||||
argv.push('0');
|
||||
}
|
||||
sections.splice.apply(sections, argv);
|
||||
}
|
||||
|
||||
result = buff || new Buffer(offset + 16);
|
||||
for (i = 0; i < sections.length; i++) {
|
||||
var word = parseInt(sections[i], 16);
|
||||
result[offset++] = (word >> 8) & 0xff;
|
||||
result[offset++] = word & 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
throw Error('Invalid ip address: ' + ip);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
ip.toString = function(buff, offset, length) {
|
||||
offset = ~~offset;
|
||||
length = length || (buff.length - offset);
|
||||
|
||||
var result = [];
|
||||
if (length === 4) {
|
||||
// IPv4
|
||||
for (var i = 0; i < length; i++) {
|
||||
result.push(buff[offset + i]);
|
||||
}
|
||||
result = result.join('.');
|
||||
} else if (length === 16) {
|
||||
// IPv6
|
||||
for (var i = 0; i < length; i += 2) {
|
||||
result.push(buff.readUInt16BE(offset + i).toString(16));
|
||||
}
|
||||
result = result.join(':');
|
||||
result = result.replace(/(^|:)0(:0)*:0(:|$)/, '$1::$3');
|
||||
result = result.replace(/:{3,4}/, '::');
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
var ipv4Regex = /^(\d{1,3}\.){3,3}\d{1,3}$/;
|
||||
var ipv6Regex =
|
||||
/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;
|
||||
|
||||
ip.isV4Format = function(ip) {
|
||||
return ipv4Regex.test(ip);
|
||||
};
|
||||
|
||||
ip.isV6Format = function(ip) {
|
||||
return ipv6Regex.test(ip);
|
||||
};
|
||||
function _normalizeFamily(family) {
|
||||
return family ? family.toLowerCase() : 'ipv4';
|
||||
}
|
||||
|
||||
ip.fromPrefixLen = function(prefixlen, family) {
|
||||
if (prefixlen > 32) {
|
||||
family = 'ipv6';
|
||||
} else {
|
||||
family = _normalizeFamily(family);
|
||||
}
|
||||
|
||||
var len = 4;
|
||||
if (family === 'ipv6') {
|
||||
len = 16;
|
||||
}
|
||||
var buff = new Buffer(len);
|
||||
|
||||
for (var i = 0, n = buff.length; i < n; ++i) {
|
||||
var bits = 8;
|
||||
if (prefixlen < 8) {
|
||||
bits = prefixlen;
|
||||
}
|
||||
prefixlen -= bits;
|
||||
|
||||
buff[i] = ~(0xff >> bits) & 0xff;
|
||||
}
|
||||
|
||||
return ip.toString(buff);
|
||||
};
|
||||
|
||||
ip.mask = function(addr, mask) {
|
||||
addr = ip.toBuffer(addr);
|
||||
mask = ip.toBuffer(mask);
|
||||
|
||||
var result = new Buffer(Math.max(addr.length, mask.length));
|
||||
|
||||
var i = 0;
|
||||
// Same protocol - do bitwise and
|
||||
if (addr.length === mask.length) {
|
||||
for (i = 0; i < addr.length; i++) {
|
||||
result[i] = addr[i] & mask[i];
|
||||
}
|
||||
} else if (mask.length === 4) {
|
||||
// IPv6 address and IPv4 mask
|
||||
// (Mask low bits)
|
||||
for (i = 0; i < mask.length; i++) {
|
||||
result[i] = addr[addr.length - 4 + i] & mask[i];
|
||||
}
|
||||
} else {
|
||||
// IPv6 mask and IPv4 addr
|
||||
for (var i = 0; i < result.length - 6; i++) {
|
||||
result[i] = 0;
|
||||
}
|
||||
|
||||
// ::ffff:ipv4
|
||||
result[10] = 0xff;
|
||||
result[11] = 0xff;
|
||||
for (i = 0; i < addr.length; i++) {
|
||||
result[i + 12] = addr[i] & mask[i + 12];
|
||||
}
|
||||
i = i + 12;
|
||||
}
|
||||
for (; i < result.length; i++)
|
||||
result[i] = 0;
|
||||
|
||||
return ip.toString(result);
|
||||
};
|
||||
|
||||
ip.cidr = function(cidrString) {
|
||||
var cidrParts = cidrString.split('/');
|
||||
|
||||
var addr = cidrParts[0];
|
||||
if (cidrParts.length !== 2)
|
||||
throw new Error('invalid CIDR subnet: ' + addr);
|
||||
|
||||
var mask = ip.fromPrefixLen(parseInt(cidrParts[1], 10));
|
||||
|
||||
return ip.mask(addr, mask);
|
||||
};
|
||||
|
||||
ip.subnet = function(addr, mask) {
|
||||
var networkAddress = ip.toLong(ip.mask(addr, mask));
|
||||
|
||||
// Calculate the mask's length.
|
||||
var maskBuffer = ip.toBuffer(mask);
|
||||
var maskLength = 0;
|
||||
|
||||
for (var i = 0; i < maskBuffer.length; i++) {
|
||||
if (maskBuffer[i] === 0xff) {
|
||||
maskLength += 8;
|
||||
} else {
|
||||
var octet = maskBuffer[i] & 0xff;
|
||||
while (octet) {
|
||||
octet = (octet << 1) & 0xff;
|
||||
maskLength++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var numberOfAddresses = Math.pow(2, 32 - maskLength);
|
||||
|
||||
return {
|
||||
networkAddress: ip.fromLong(networkAddress),
|
||||
firstAddress: numberOfAddresses <= 2 ?
|
||||
ip.fromLong(networkAddress) :
|
||||
ip.fromLong(networkAddress + 1),
|
||||
lastAddress: numberOfAddresses <= 2 ?
|
||||
ip.fromLong(networkAddress + numberOfAddresses - 1) :
|
||||
ip.fromLong(networkAddress + numberOfAddresses - 2),
|
||||
broadcastAddress: ip.fromLong(networkAddress + numberOfAddresses - 1),
|
||||
subnetMask: mask,
|
||||
subnetMaskLength: maskLength,
|
||||
numHosts: numberOfAddresses <= 2 ?
|
||||
numberOfAddresses : numberOfAddresses - 2,
|
||||
length: numberOfAddresses,
|
||||
contains: function(other) {
|
||||
return networkAddress === ip.toLong(ip.mask(other, mask));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
ip.cidrSubnet = function(cidrString) {
|
||||
var cidrParts = cidrString.split('/');
|
||||
|
||||
var addr = cidrParts[0];
|
||||
if (cidrParts.length !== 2)
|
||||
throw new Error('invalid CIDR subnet: ' + addr);
|
||||
|
||||
var mask = ip.fromPrefixLen(parseInt(cidrParts[1], 10));
|
||||
|
||||
return ip.subnet(addr, mask);
|
||||
};
|
||||
|
||||
ip.not = function(addr) {
|
||||
var buff = ip.toBuffer(addr);
|
||||
for (var i = 0; i < buff.length; i++) {
|
||||
buff[i] = 0xff ^ buff[i];
|
||||
}
|
||||
return ip.toString(buff);
|
||||
};
|
||||
|
||||
ip.or = function(a, b) {
|
||||
a = ip.toBuffer(a);
|
||||
b = ip.toBuffer(b);
|
||||
|
||||
// same protocol
|
||||
if (a.length === b.length) {
|
||||
for (var i = 0; i < a.length; ++i) {
|
||||
a[i] |= b[i];
|
||||
}
|
||||
return ip.toString(a);
|
||||
|
||||
// mixed protocols
|
||||
} else {
|
||||
var buff = a;
|
||||
var other = b;
|
||||
if (b.length > a.length) {
|
||||
buff = b;
|
||||
other = a;
|
||||
}
|
||||
|
||||
var offset = buff.length - other.length;
|
||||
for (var i = offset; i < buff.length; ++i) {
|
||||
buff[i] |= other[i - offset];
|
||||
}
|
||||
|
||||
return ip.toString(buff);
|
||||
}
|
||||
};
|
||||
|
||||
ip.isEqual = function(a, b) {
|
||||
a = ip.toBuffer(a);
|
||||
b = ip.toBuffer(b);
|
||||
|
||||
// Same protocol
|
||||
if (a.length === b.length) {
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
if (a[i] !== b[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Swap
|
||||
if (b.length === 4) {
|
||||
var t = b;
|
||||
b = a;
|
||||
a = t;
|
||||
}
|
||||
|
||||
// a - IPv4, b - IPv6
|
||||
for (var i = 0; i < 10; i++) {
|
||||
if (b[i] !== 0) return false;
|
||||
}
|
||||
|
||||
var word = b.readUInt16BE(10);
|
||||
if (word !== 0 && word !== 0xffff) return false;
|
||||
|
||||
for (var i = 0; i < 4; i++) {
|
||||
if (a[i] !== b[i + 12]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
ip.isPrivate = function(addr) {
|
||||
return /^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i
|
||||
.test(addr) ||
|
||||
/^(::f{4}:)?192\.168\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(addr) ||
|
||||
/^(::f{4}:)?172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})$/i
|
||||
.test(addr) ||
|
||||
/^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(addr) ||
|
||||
/^(::f{4}:)?169\.254\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(addr) ||
|
||||
/^f[cd][0-9a-f]{2}:/i.test(addr) ||
|
||||
/^fe80:/i.test(addr) ||
|
||||
/^::1$/.test(addr) ||
|
||||
/^::$/.test(addr);
|
||||
};
|
||||
|
||||
ip.isPublic = function(addr) {
|
||||
return !ip.isPrivate(addr);
|
||||
};
|
||||
|
||||
ip.isLoopback = function(addr) {
|
||||
return /^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/
|
||||
.test(addr) ||
|
||||
/^fe80::1$/.test(addr) ||
|
||||
/^::1$/.test(addr) ||
|
||||
/^::$/.test(addr);
|
||||
};
|
||||
|
||||
ip.loopback = function(family) {
|
||||
//
|
||||
// Default to `ipv4`
|
||||
//
|
||||
family = _normalizeFamily(family);
|
||||
|
||||
if (family !== 'ipv4' && family !== 'ipv6') {
|
||||
throw new Error('family must be ipv4 or ipv6');
|
||||
}
|
||||
|
||||
return family === 'ipv4' ? '127.0.0.1' : 'fe80::1';
|
||||
};
|
||||
|
||||
//
|
||||
// ### function address (name, family)
|
||||
// #### @name {string|'public'|'private'} **Optional** Name or security
|
||||
// of the network interface.
|
||||
// #### @family {ipv4|ipv6} **Optional** IP family of the address (defaults
|
||||
// to ipv4).
|
||||
//
|
||||
// Returns the address for the network interface on the current system with
|
||||
// the specified `name`:
|
||||
// * String: First `family` address of the interface.
|
||||
// If not found see `undefined`.
|
||||
// * 'public': the first public ip address of family.
|
||||
// * 'private': the first private ip address of family.
|
||||
// * undefined: First address with `ipv4` or loopback address `127.0.0.1`.
|
||||
//
|
||||
ip.address = function(name, family) {
|
||||
var interfaces = os.networkInterfaces();
|
||||
var all;
|
||||
|
||||
//
|
||||
// Default to `ipv4`
|
||||
//
|
||||
family = _normalizeFamily(family);
|
||||
|
||||
//
|
||||
// If a specific network interface has been named,
|
||||
// return the address.
|
||||
//
|
||||
if (name && name !== 'private' && name !== 'public') {
|
||||
var res = interfaces[name].filter(function(details) {
|
||||
var itemFamily = details.family.toLowerCase();
|
||||
return itemFamily === family;
|
||||
});
|
||||
if (res.length === 0)
|
||||
return undefined;
|
||||
return res[0].address;
|
||||
}
|
||||
|
||||
var all = Object.keys(interfaces).map(function (nic) {
|
||||
//
|
||||
// Note: name will only be `public` or `private`
|
||||
// when this is called.
|
||||
//
|
||||
var addresses = interfaces[nic].filter(function (details) {
|
||||
details.family = details.family.toLowerCase();
|
||||
if (details.family !== family || ip.isLoopback(details.address)) {
|
||||
return false;
|
||||
} else if (!name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return name === 'public' ? ip.isPrivate(details.address) :
|
||||
ip.isPublic(details.address);
|
||||
});
|
||||
|
||||
return addresses.length ? addresses[0].address : undefined;
|
||||
}).filter(Boolean);
|
||||
|
||||
return !all.length ? ip.loopback(family) : all[0];
|
||||
};
|
||||
|
||||
ip.toLong = function(ip) {
|
||||
var ipl = 0;
|
||||
ip.split('.').forEach(function(octet) {
|
||||
ipl <<= 8;
|
||||
ipl += parseInt(octet);
|
||||
});
|
||||
return(ipl >>> 0);
|
||||
};
|
||||
|
||||
ip.fromLong = function(ipl) {
|
||||
return ((ipl >>> 24) + '.' +
|
||||
(ipl >> 16 & 255) + '.' +
|
||||
(ipl >> 8 & 255) + '.' +
|
||||
(ipl & 255) );
|
||||
};
|
21
node_modules/ip/package.json
generated
vendored
Normal file
21
node_modules/ip/package.json
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "ip",
|
||||
"version": "1.1.5",
|
||||
"author": "Fedor Indutny <fedor@indutny.com>",
|
||||
"homepage": "https://github.com/indutny/node-ip",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "http://github.com/indutny/node-ip.git"
|
||||
},
|
||||
"main": "lib/ip",
|
||||
"devDependencies": {
|
||||
"jscs": "^2.1.1",
|
||||
"jshint": "^2.8.0",
|
||||
"mocha": "~1.3.2"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "jscs lib/*.js test/*.js && jshint lib/*.js && mocha --reporter spec test/*-test.js",
|
||||
"fix": "jscs lib/*.js test/*.js --fix"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
407
node_modules/ip/test/api-test.js
generated
vendored
Normal file
407
node_modules/ip/test/api-test.js
generated
vendored
Normal file
@ -0,0 +1,407 @@
|
||||
'use strict';
|
||||
|
||||
var ip = require('..');
|
||||
var assert = require('assert');
|
||||
var net = require('net');
|
||||
var os = require('os');
|
||||
|
||||
describe('IP library for node.js', function() {
|
||||
describe('toBuffer()/toString() methods', function() {
|
||||
it('should convert to buffer IPv4 address', function() {
|
||||
var buf = ip.toBuffer('127.0.0.1');
|
||||
assert.equal(buf.toString('hex'), '7f000001');
|
||||
assert.equal(ip.toString(buf), '127.0.0.1');
|
||||
});
|
||||
|
||||
it('should convert to buffer IPv4 address in-place', function() {
|
||||
var buf = new Buffer(128);
|
||||
var offset = 64;
|
||||
ip.toBuffer('127.0.0.1', buf, offset);
|
||||
assert.equal(buf.toString('hex', offset, offset + 4), '7f000001');
|
||||
assert.equal(ip.toString(buf, offset, 4), '127.0.0.1');
|
||||
});
|
||||
|
||||
it('should convert to buffer IPv6 address', function() {
|
||||
var buf = ip.toBuffer('::1');
|
||||
assert(/(00){15,15}01/.test(buf.toString('hex')));
|
||||
assert.equal(ip.toString(buf), '::1');
|
||||
assert.equal(ip.toString(ip.toBuffer('1::')), '1::');
|
||||
assert.equal(ip.toString(ip.toBuffer('abcd::dcba')), 'abcd::dcba');
|
||||
});
|
||||
|
||||
it('should convert to buffer IPv6 address in-place', function() {
|
||||
var buf = new Buffer(128);
|
||||
var offset = 64;
|
||||
ip.toBuffer('::1', buf, offset);
|
||||
assert(/(00){15,15}01/.test(buf.toString('hex', offset, offset + 16)));
|
||||
assert.equal(ip.toString(buf, offset, 16), '::1');
|
||||
assert.equal(ip.toString(ip.toBuffer('1::', buf, offset),
|
||||
offset, 16), '1::');
|
||||
assert.equal(ip.toString(ip.toBuffer('abcd::dcba', buf, offset),
|
||||
offset, 16), 'abcd::dcba');
|
||||
});
|
||||
|
||||
it('should convert to buffer IPv6 mapped IPv4 address', function() {
|
||||
var buf = ip.toBuffer('::ffff:127.0.0.1');
|
||||
assert.equal(buf.toString('hex'), '00000000000000000000ffff7f000001');
|
||||
assert.equal(ip.toString(buf), '::ffff:7f00:1');
|
||||
|
||||
buf = ip.toBuffer('ffff::127.0.0.1');
|
||||
assert.equal(buf.toString('hex'), 'ffff000000000000000000007f000001');
|
||||
assert.equal(ip.toString(buf), 'ffff::7f00:1');
|
||||
|
||||
buf = ip.toBuffer('0:0:0:0:0:ffff:127.0.0.1');
|
||||
assert.equal(buf.toString('hex'), '00000000000000000000ffff7f000001');
|
||||
assert.equal(ip.toString(buf), '::ffff:7f00:1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('fromPrefixLen() method', function() {
|
||||
it('should create IPv4 mask', function() {
|
||||
assert.equal(ip.fromPrefixLen(24), '255.255.255.0');
|
||||
});
|
||||
it('should create IPv6 mask', function() {
|
||||
assert.equal(ip.fromPrefixLen(64), 'ffff:ffff:ffff:ffff::');
|
||||
});
|
||||
it('should create IPv6 mask explicitly', function() {
|
||||
assert.equal(ip.fromPrefixLen(24, 'IPV6'), 'ffff:ff00::');
|
||||
});
|
||||
});
|
||||
|
||||
describe('not() method', function() {
|
||||
it('should reverse bits in address', function() {
|
||||
assert.equal(ip.not('255.255.255.0'), '0.0.0.255');
|
||||
});
|
||||
});
|
||||
|
||||
describe('or() method', function() {
|
||||
it('should or bits in ipv4 addresses', function() {
|
||||
assert.equal(ip.or('0.0.0.255', '192.168.1.10'), '192.168.1.255');
|
||||
});
|
||||
it('should or bits in ipv6 addresses', function() {
|
||||
assert.equal(ip.or('::ff', '::abcd:dcba:abcd:dcba'),
|
||||
'::abcd:dcba:abcd:dcff');
|
||||
});
|
||||
it('should or bits in mixed addresses', function() {
|
||||
assert.equal(ip.or('0.0.0.255', '::abcd:dcba:abcd:dcba'),
|
||||
'::abcd:dcba:abcd:dcff');
|
||||
});
|
||||
});
|
||||
|
||||
describe('mask() method', function() {
|
||||
it('should mask bits in address', function() {
|
||||
assert.equal(ip.mask('192.168.1.134', '255.255.255.0'), '192.168.1.0');
|
||||
assert.equal(ip.mask('192.168.1.134', '::ffff:ff00'), '::ffff:c0a8:100');
|
||||
});
|
||||
|
||||
it('should not leak data', function() {
|
||||
for (var i = 0; i < 10; i++)
|
||||
assert.equal(ip.mask('::1', '0.0.0.0'), '::');
|
||||
});
|
||||
});
|
||||
|
||||
describe('subnet() method', function() {
|
||||
// Test cases calculated with http://www.subnet-calculator.com/
|
||||
var ipv4Subnet = ip.subnet('192.168.1.134', '255.255.255.192');
|
||||
|
||||
it('should compute ipv4 network address', function() {
|
||||
assert.equal(ipv4Subnet.networkAddress, '192.168.1.128');
|
||||
});
|
||||
|
||||
it('should compute ipv4 network\'s first address', function() {
|
||||
assert.equal(ipv4Subnet.firstAddress, '192.168.1.129');
|
||||
});
|
||||
|
||||
it('should compute ipv4 network\'s last address', function() {
|
||||
assert.equal(ipv4Subnet.lastAddress, '192.168.1.190');
|
||||
});
|
||||
|
||||
it('should compute ipv4 broadcast address', function() {
|
||||
assert.equal(ipv4Subnet.broadcastAddress, '192.168.1.191');
|
||||
});
|
||||
|
||||
it('should compute ipv4 subnet number of addresses', function() {
|
||||
assert.equal(ipv4Subnet.length, 64);
|
||||
});
|
||||
|
||||
it('should compute ipv4 subnet number of addressable hosts', function() {
|
||||
assert.equal(ipv4Subnet.numHosts, 62);
|
||||
});
|
||||
|
||||
it('should compute ipv4 subnet mask', function() {
|
||||
assert.equal(ipv4Subnet.subnetMask, '255.255.255.192');
|
||||
});
|
||||
|
||||
it('should compute ipv4 subnet mask\'s length', function() {
|
||||
assert.equal(ipv4Subnet.subnetMaskLength, 26);
|
||||
});
|
||||
|
||||
it('should know whether a subnet contains an address', function() {
|
||||
assert.equal(ipv4Subnet.contains('192.168.1.180'), true);
|
||||
});
|
||||
|
||||
it('should know whether a subnet does not contain an address', function() {
|
||||
assert.equal(ipv4Subnet.contains('192.168.1.195'), false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('subnet() method with mask length 32', function() {
|
||||
// Test cases calculated with http://www.subnet-calculator.com/
|
||||
var ipv4Subnet = ip.subnet('192.168.1.134', '255.255.255.255');
|
||||
it('should compute ipv4 network\'s first address', function() {
|
||||
assert.equal(ipv4Subnet.firstAddress, '192.168.1.134');
|
||||
});
|
||||
|
||||
it('should compute ipv4 network\'s last address', function() {
|
||||
assert.equal(ipv4Subnet.lastAddress, '192.168.1.134');
|
||||
});
|
||||
|
||||
it('should compute ipv4 subnet number of addressable hosts', function() {
|
||||
assert.equal(ipv4Subnet.numHosts, 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('subnet() method with mask length 31', function() {
|
||||
// Test cases calculated with http://www.subnet-calculator.com/
|
||||
var ipv4Subnet = ip.subnet('192.168.1.134', '255.255.255.254');
|
||||
it('should compute ipv4 network\'s first address', function() {
|
||||
assert.equal(ipv4Subnet.firstAddress, '192.168.1.134');
|
||||
});
|
||||
|
||||
it('should compute ipv4 network\'s last address', function() {
|
||||
assert.equal(ipv4Subnet.lastAddress, '192.168.1.135');
|
||||
});
|
||||
|
||||
it('should compute ipv4 subnet number of addressable hosts', function() {
|
||||
assert.equal(ipv4Subnet.numHosts, 2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('cidrSubnet() method', function() {
|
||||
// Test cases calculated with http://www.subnet-calculator.com/
|
||||
var ipv4Subnet = ip.cidrSubnet('192.168.1.134/26');
|
||||
|
||||
it('should compute an ipv4 network address', function() {
|
||||
assert.equal(ipv4Subnet.networkAddress, '192.168.1.128');
|
||||
});
|
||||
|
||||
it('should compute an ipv4 network\'s first address', function() {
|
||||
assert.equal(ipv4Subnet.firstAddress, '192.168.1.129');
|
||||
});
|
||||
|
||||
it('should compute an ipv4 network\'s last address', function() {
|
||||
assert.equal(ipv4Subnet.lastAddress, '192.168.1.190');
|
||||
});
|
||||
|
||||
it('should compute an ipv4 broadcast address', function() {
|
||||
assert.equal(ipv4Subnet.broadcastAddress, '192.168.1.191');
|
||||
});
|
||||
|
||||
it('should compute an ipv4 subnet number of addresses', function() {
|
||||
assert.equal(ipv4Subnet.length, 64);
|
||||
});
|
||||
|
||||
it('should compute an ipv4 subnet number of addressable hosts', function() {
|
||||
assert.equal(ipv4Subnet.numHosts, 62);
|
||||
});
|
||||
|
||||
it('should compute an ipv4 subnet mask', function() {
|
||||
assert.equal(ipv4Subnet.subnetMask, '255.255.255.192');
|
||||
});
|
||||
|
||||
it('should compute an ipv4 subnet mask\'s length', function() {
|
||||
assert.equal(ipv4Subnet.subnetMaskLength, 26);
|
||||
});
|
||||
|
||||
it('should know whether a subnet contains an address', function() {
|
||||
assert.equal(ipv4Subnet.contains('192.168.1.180'), true);
|
||||
});
|
||||
|
||||
it('should know whether a subnet contains an address', function() {
|
||||
assert.equal(ipv4Subnet.contains('192.168.1.195'), false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('cidr() method', function() {
|
||||
it('should mask address in CIDR notation', function() {
|
||||
assert.equal(ip.cidr('192.168.1.134/26'), '192.168.1.128');
|
||||
assert.equal(ip.cidr('2607:f0d0:1002:51::4/56'), '2607:f0d0:1002::');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isEqual() method', function() {
|
||||
it('should check if addresses are equal', function() {
|
||||
assert(ip.isEqual('127.0.0.1', '::7f00:1'));
|
||||
assert(!ip.isEqual('127.0.0.1', '::7f00:2'));
|
||||
assert(ip.isEqual('127.0.0.1', '::ffff:7f00:1'));
|
||||
assert(!ip.isEqual('127.0.0.1', '::ffaf:7f00:1'));
|
||||
assert(ip.isEqual('::ffff:127.0.0.1', '::ffff:127.0.0.1'));
|
||||
assert(ip.isEqual('::ffff:127.0.0.1', '127.0.0.1'));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('isPrivate() method', function() {
|
||||
it('should check if an address is localhost', function() {
|
||||
assert.equal(ip.isPrivate('127.0.0.1'), true);
|
||||
});
|
||||
|
||||
it('should check if an address is from a 192.168.x.x network', function() {
|
||||
assert.equal(ip.isPrivate('192.168.0.123'), true);
|
||||
assert.equal(ip.isPrivate('192.168.122.123'), true);
|
||||
assert.equal(ip.isPrivate('192.162.1.2'), false);
|
||||
});
|
||||
|
||||
it('should check if an address is from a 172.16.x.x network', function() {
|
||||
assert.equal(ip.isPrivate('172.16.0.5'), true);
|
||||
assert.equal(ip.isPrivate('172.16.123.254'), true);
|
||||
assert.equal(ip.isPrivate('171.16.0.5'), false);
|
||||
assert.equal(ip.isPrivate('172.25.232.15'), true);
|
||||
assert.equal(ip.isPrivate('172.15.0.5'), false);
|
||||
assert.equal(ip.isPrivate('172.32.0.5'), false);
|
||||
});
|
||||
|
||||
it('should check if an address is from a 169.254.x.x network', function() {
|
||||
assert.equal(ip.isPrivate('169.254.2.3'), true);
|
||||
assert.equal(ip.isPrivate('169.254.221.9'), true);
|
||||
assert.equal(ip.isPrivate('168.254.2.3'), false);
|
||||
});
|
||||
|
||||
it('should check if an address is from a 10.x.x.x network', function() {
|
||||
assert.equal(ip.isPrivate('10.0.2.3'), true);
|
||||
assert.equal(ip.isPrivate('10.1.23.45'), true);
|
||||
assert.equal(ip.isPrivate('12.1.2.3'), false);
|
||||
});
|
||||
|
||||
it('should check if an address is from a private IPv6 network', function() {
|
||||
assert.equal(ip.isPrivate('fd12:3456:789a:1::1'), true);
|
||||
assert.equal(ip.isPrivate('fe80::f2de:f1ff:fe3f:307e'), true);
|
||||
assert.equal(ip.isPrivate('::ffff:10.100.1.42'), true);
|
||||
assert.equal(ip.isPrivate('::FFFF:172.16.200.1'), true);
|
||||
assert.equal(ip.isPrivate('::ffff:192.168.0.1'), true);
|
||||
});
|
||||
|
||||
it('should check if an address is from the internet', function() {
|
||||
assert.equal(ip.isPrivate('165.225.132.33'), false); // joyent.com
|
||||
});
|
||||
|
||||
it('should check if an address is a loopback IPv6 address', function() {
|
||||
assert.equal(ip.isPrivate('::'), true);
|
||||
assert.equal(ip.isPrivate('::1'), true);
|
||||
assert.equal(ip.isPrivate('fe80::1'), true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('loopback() method', function() {
|
||||
describe('undefined', function() {
|
||||
it('should respond with 127.0.0.1', function() {
|
||||
assert.equal(ip.loopback(), '127.0.0.1')
|
||||
});
|
||||
});
|
||||
|
||||
describe('ipv4', function() {
|
||||
it('should respond with 127.0.0.1', function() {
|
||||
assert.equal(ip.loopback('ipv4'), '127.0.0.1')
|
||||
});
|
||||
});
|
||||
|
||||
describe('ipv6', function() {
|
||||
it('should respond with fe80::1', function() {
|
||||
assert.equal(ip.loopback('ipv6'), 'fe80::1')
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isLoopback() method', function() {
|
||||
describe('127.0.0.1', function() {
|
||||
it('should respond with true', function() {
|
||||
assert.ok(ip.isLoopback('127.0.0.1'))
|
||||
});
|
||||
});
|
||||
|
||||
describe('127.8.8.8', function () {
|
||||
it('should respond with true', function () {
|
||||
assert.ok(ip.isLoopback('127.8.8.8'))
|
||||
});
|
||||
});
|
||||
|
||||
describe('8.8.8.8', function () {
|
||||
it('should respond with false', function () {
|
||||
assert.equal(ip.isLoopback('8.8.8.8'), false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fe80::1', function() {
|
||||
it('should respond with true', function() {
|
||||
assert.ok(ip.isLoopback('fe80::1'))
|
||||
});
|
||||
});
|
||||
|
||||
describe('::1', function() {
|
||||
it('should respond with true', function() {
|
||||
assert.ok(ip.isLoopback('::1'))
|
||||
});
|
||||
});
|
||||
|
||||
describe('::', function() {
|
||||
it('should respond with true', function() {
|
||||
assert.ok(ip.isLoopback('::'))
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('address() method', function() {
|
||||
describe('undefined', function() {
|
||||
it('should respond with a private ip', function() {
|
||||
assert.ok(ip.isPrivate(ip.address()));
|
||||
});
|
||||
});
|
||||
|
||||
describe('private', function() {
|
||||
[ undefined, 'ipv4', 'ipv6' ].forEach(function(family) {
|
||||
describe(family, function() {
|
||||
it('should respond with a private ip', function() {
|
||||
assert.ok(ip.isPrivate(ip.address('private', family)));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var interfaces = os.networkInterfaces();
|
||||
|
||||
Object.keys(interfaces).forEach(function(nic) {
|
||||
describe(nic, function() {
|
||||
[ undefined, 'ipv4' ].forEach(function(family) {
|
||||
describe(family, function() {
|
||||
it('should respond with an ipv4 address', function() {
|
||||
var addr = ip.address(nic, family);
|
||||
assert.ok(!addr || net.isIPv4(addr));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('ipv6', function() {
|
||||
it('should respond with an ipv6 address', function() {
|
||||
var addr = ip.address(nic, 'ipv6');
|
||||
assert.ok(!addr || net.isIPv6(addr));
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('toLong() method', function() {
|
||||
it('should respond with a int', function() {
|
||||
assert.equal(ip.toLong('127.0.0.1'), 2130706433);
|
||||
assert.equal(ip.toLong('255.255.255.255'), 4294967295);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fromLong() method', function() {
|
||||
it('should repond with ipv4 address', function() {
|
||||
assert.equal(ip.fromLong(2130706433), '127.0.0.1');
|
||||
assert.equal(ip.fromLong(4294967295), '255.255.255.255');
|
||||
});
|
||||
})
|
||||
});
|
2
node_modules/jsbn/.npmignore
generated
vendored
Normal file
2
node_modules/jsbn/.npmignore
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
.DS_Store
|
16
node_modules/jsbn/CHANGELOG.md
generated
vendored
Normal file
16
node_modules/jsbn/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
# v1.1.0
|
||||
|
||||
- Allow for es6 "default import", e.g. `import BigInteger from 'jsbn'`.
|
||||
- Updated license file to read MIT
|
||||
|
||||
|
||||
# v1.0.0
|
||||
|
||||
- breaking change: `require('jsbn')` no longer returns `BigInteger`. Use `require('jsbn').BigInteger` instead.
|
||||
|
||||
|
||||
|
||||
# v0.1.1
|
||||
|
||||
- fixed backwards-incompatible change in v0.1.0 where `require('jsbn') != BigInteger`. This patch version allows for `var BigInteger = require('jsbn')` or `var BigInteger = require('jsbn').BigInteger`.
|
||||
|
40
node_modules/jsbn/LICENSE
generated
vendored
Normal file
40
node_modules/jsbn/LICENSE
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
Licensing
|
||||
---------
|
||||
|
||||
This software is covered under the following copyright:
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003-2005 Tom Wu
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
|
||||
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
|
||||
* THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
|
||||
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* In addition, the following condition applies:
|
||||
*
|
||||
* All redistributions must retain an intact copy of this copyright notice
|
||||
* and disclaimer.
|
||||
*/
|
||||
|
||||
Address all questions regarding this license to:
|
||||
|
||||
Tom Wu
|
||||
tjw@cs.Stanford.EDU
|
173
node_modules/jsbn/README.md
generated
vendored
Normal file
173
node_modules/jsbn/README.md
generated
vendored
Normal file
@ -0,0 +1,173 @@
|
||||
# jsbn: javascript big number
|
||||
|
||||
[Tom Wu's Original Website](http://www-cs-students.stanford.edu/~tjw/jsbn/)
|
||||
|
||||
I felt compelled to put this on github and publish to npm. I haven't tested every other big integer library out there, but the few that I have tested in comparison to this one have not even come close in performance. I am aware of the `bi` module on npm, however it has been modified and I wanted to publish the original without modifications. This is jsbn and jsbn2 from Tom Wu's original website above, with the module pattern applied to prevent global leaks and to allow for use with node.js on the server side.
|
||||
|
||||
## usage
|
||||
|
||||
var BigInteger = require('jsbn').BigInteger;
|
||||
|
||||
var bi = new BigInteger('91823918239182398123');
|
||||
console.log(bi.bitLength()); // 67
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### bi.toString()
|
||||
|
||||
returns the base-10 number as a string
|
||||
|
||||
### bi.negate()
|
||||
|
||||
returns a new BigInteger equal to the negation of `bi`
|
||||
|
||||
### bi.abs
|
||||
|
||||
returns new BI of absolute value
|
||||
|
||||
### bi.compareTo
|
||||
|
||||
|
||||
|
||||
### bi.bitLength
|
||||
|
||||
|
||||
|
||||
### bi.mod
|
||||
|
||||
|
||||
|
||||
### bi.modPowInt
|
||||
|
||||
|
||||
|
||||
### bi.clone
|
||||
|
||||
|
||||
|
||||
### bi.intValue
|
||||
|
||||
|
||||
|
||||
### bi.byteValue
|
||||
|
||||
|
||||
|
||||
### bi.shortValue
|
||||
|
||||
|
||||
|
||||
### bi.signum
|
||||
|
||||
|
||||
|
||||
### bi.toByteArray
|
||||
|
||||
|
||||
|
||||
### bi.equals
|
||||
|
||||
|
||||
|
||||
### bi.min
|
||||
|
||||
|
||||
|
||||
### bi.max
|
||||
|
||||
|
||||
|
||||
### bi.and
|
||||
|
||||
|
||||
|
||||
### bi.or
|
||||
|
||||
|
||||
|
||||
### bi.xor
|
||||
|
||||
|
||||
|
||||
### bi.andNot
|
||||
|
||||
|
||||
|
||||
### bi.not
|
||||
|
||||
|
||||
|
||||
### bi.shiftLeft
|
||||
|
||||
|
||||
|
||||
### bi.shiftRight
|
||||
|
||||
|
||||
|
||||
### bi.getLowestSetBit
|
||||
|
||||
|
||||
|
||||
### bi.bitCount
|
||||
|
||||
|
||||
|
||||
### bi.testBit
|
||||
|
||||
|
||||
|
||||
### bi.setBit
|
||||
|
||||
|
||||
|
||||
### bi.clearBit
|
||||
|
||||
|
||||
|
||||
### bi.flipBit
|
||||
|
||||
|
||||
|
||||
### bi.add
|
||||
|
||||
|
||||
|
||||
### bi.subtract
|
||||
|
||||
|
||||
|
||||
### bi.multiply
|
||||
|
||||
|
||||
|
||||
### bi.divide
|
||||
|
||||
|
||||
|
||||
### bi.remainder
|
||||
|
||||
|
||||
|
||||
### bi.divideAndRemainder
|
||||
|
||||
|
||||
|
||||
### bi.modPow
|
||||
|
||||
|
||||
|
||||
### bi.modInverse
|
||||
|
||||
|
||||
|
||||
### bi.pow
|
||||
|
||||
|
||||
|
||||
### bi.gcd
|
||||
|
||||
|
||||
|
||||
### bi.isProbablePrime
|
11
node_modules/jsbn/example.html
generated
vendored
Normal file
11
node_modules/jsbn/example.html
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<script src="index.js"></script>
|
||||
<script src="example.js"></script>
|
||||
</body>
|
||||
</html>
|
5
node_modules/jsbn/example.js
generated
vendored
Normal file
5
node_modules/jsbn/example.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
(function () {
|
||||
var BigInteger = jsbn.BigInteger;
|
||||
var a = new BigInteger('91823918239182398123');
|
||||
console.log(a.bitLength());
|
||||
}());
|
1361
node_modules/jsbn/index.js
generated
vendored
Normal file
1361
node_modules/jsbn/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
21
node_modules/jsbn/package.json
generated
vendored
Normal file
21
node_modules/jsbn/package.json
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "jsbn",
|
||||
"version": "1.1.0",
|
||||
"description": "The jsbn library is a fast, portable implementation of large-number math in pure JavaScript, enabling public-key crypto and other applications on desktop and mobile browsers.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "mocha test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/andyperlitch/jsbn.git"
|
||||
},
|
||||
"keywords": [
|
||||
"biginteger",
|
||||
"bignumber",
|
||||
"big",
|
||||
"integer"
|
||||
],
|
||||
"author": "Tom Wu",
|
||||
"license": "MIT"
|
||||
}
|
3
node_modules/jsbn/test/es6-import.js
generated
vendored
Normal file
3
node_modules/jsbn/test/es6-import.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import {BigInteger} from '../';
|
||||
|
||||
console.log(typeof BigInteger)
|
41
node_modules/local-devices/CHANGES.md
generated
vendored
Normal file
41
node_modules/local-devices/CHANGES.md
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
# Local-Devices
|
||||
|
||||
All notable changes to this project will be documented here. The format is based
|
||||
on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project
|
||||
adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [3.1.0] - 2020-09-25
|
||||
|
||||
### Added
|
||||
|
||||
- support passing ip ranges to the `find` api ([#24](https://github.com/DylanPiercey/local-devices/pull/24))
|
||||
|
||||
## [3.0.0] - 2019-10-29
|
||||
|
||||
### Changed
|
||||
|
||||
⚠ BREAKING CHANGES
|
||||
|
||||
- dropping Node v8 support because [end-of-life](https://github.com/nodejs/Release#release-schedule)
|
||||
[[#18](https://github.com/DylanPiercey/local-devices/pull/18)]
|
||||
|
||||
### Fixes
|
||||
|
||||
- increase `maxBuffer` of `cp.exec` to 10MB (1024*1024*10), fixes [#10](https://github.com/DylanPiercey/local-devices/issues/10)
|
||||
- fix: add timeout options when exec arp ([#13](https://github.com/DylanPiercey/local-devices/pull/13))
|
||||
- Fixed win32 parser for better windows support ([#9](https://github.com/DylanPiercey/local-devices/pull/9))
|
||||
- validate ip address before executing command for 'find' ([#16](https://github.com/DylanPiercey/local-devices/pull/16))
|
||||
|
||||
## [2.0.0] - 2019-02-10
|
||||
|
||||
### Added
|
||||
|
||||
- Support for Raspberry Pi (Linux)
|
||||
- Partial support for windows
|
||||
- Jest test suite and tests for Linux and other platforms
|
||||
- with Travis CI integration
|
||||
|
||||
### Changed
|
||||
|
||||
- fixed npm module versions in package.json
|
||||
- fixed node version to v8.14.1
|
21
node_modules/local-devices/LICENCE
generated
vendored
Normal file
21
node_modules/local-devices/LICENCE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018, Dylan Piercey and Contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
145
node_modules/local-devices/README.md
generated
vendored
Normal file
145
node_modules/local-devices/README.md
generated
vendored
Normal file
@ -0,0 +1,145 @@
|
||||
# Local Devices
|
||||
|
||||
[![version][version-badge]][package]
|
||||
[![MIT License][license-badge]][licence]
|
||||
[](http://standardjs.com/)
|
||||
[](#contributors)
|
||||
[![PRs Welcome][prs-badge]][prs]
|
||||
|
||||
[![Build Status][build-badge]][build]
|
||||
[![Coverage Status][coverage-badge]][coverage]
|
||||
[![Watch on GitHub][github-watch-badge]][github-watch]
|
||||
[![Star on GitHub][github-star-badge]][github-star]
|
||||
|
||||
Find all devices connected to the local network using `arp -a`.
|
||||
This module also pings all possible ip's in the local network to build the arp table.
|
||||
|
||||
## Installation
|
||||
|
||||
### Npm
|
||||
|
||||
```console
|
||||
npm install local-devices
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
// Using a transpiler
|
||||
import find from 'local-devices'
|
||||
// Without using a transpiler
|
||||
const find = require('local-devices');
|
||||
|
||||
// Find all local network devices.
|
||||
find().then(devices => {
|
||||
devices /*
|
||||
[
|
||||
{ name: '?', ip: '192.168.0.10', mac: '...' },
|
||||
{ name: '...', ip: '192.168.0.17', mac: '...' },
|
||||
{ name: '...', ip: '192.168.0.21', mac: '...' },
|
||||
{ name: '...', ip: '192.168.0.22', mac: '...' }
|
||||
]
|
||||
*/
|
||||
})
|
||||
|
||||
// Find a single device by ip address.
|
||||
find('192.168.0.10').then(device => {
|
||||
device /*
|
||||
{
|
||||
name: '?',
|
||||
ip: '192.168.0.10',
|
||||
mac: '...'
|
||||
}
|
||||
*/
|
||||
})
|
||||
|
||||
// Find all devices within 192.168.0.1 to 192.168.0.25 range
|
||||
find('192.168.0.1-192.168.0.25').then(devices => {
|
||||
devices /*
|
||||
[
|
||||
{ name: '?', ip: '192.168.0.10', mac: '...' },
|
||||
{ name: '...', ip: '192.168.0.17', mac: '...' },
|
||||
{ name: '...', ip: '192.168.0.21', mac: '...' },
|
||||
{ name: '...', ip: '192.168.0.22', mac: '...' }
|
||||
]
|
||||
*/
|
||||
})
|
||||
|
||||
// Find all devices within /24 subnet range of 192.168.0.x
|
||||
find('192.168.0.0/24').then(devices => {
|
||||
devices /*
|
||||
[
|
||||
{ name: '?', ip: '192.168.0.10', mac: '...' },
|
||||
{ name: '...', ip: '192.168.0.50', mac: '...' },
|
||||
{ name: '...', ip: '192.168.0.155', mac: '...' },
|
||||
{ name: '...', ip: '192.168.0.211', mac: '...' }
|
||||
]
|
||||
*/
|
||||
})
|
||||
```
|
||||
|
||||
## Contributions
|
||||
|
||||
* Use `npm test` to run tests.
|
||||
|
||||
Please feel free to create a PR!
|
||||
|
||||
## Contributors
|
||||
|
||||
Thanks goes to these wonderful people ([emoji key][emojis]):
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
||||
<!-- prettier-ignore-start -->
|
||||
<!-- markdownlint-disable -->
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center"><a href="https://twitter.com/dylan_piercey"><img src="https://avatars2.githubusercontent.com/u/4985201?v=4" width="100px;" alt="Dylan Piercey"/><br /><sub><b>Dylan Piercey</b></sub></a><br /><a href="https://github.com/DylanPiercey/local-devices/commits?author=DylanPiercey" title="Code">💻</a> <a href="#example-DylanPiercey" title="Examples">💡</a> <a href="#review-DylanPiercey" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/DylanPiercey/local-devices/commits?author=DylanPiercey" title="Documentation">📖</a> <a href="#ideas-DylanPiercey" title="Ideas, Planning, & Feedback">🤔</a> <a href="#question-DylanPiercey" title="Answering Questions">💬</a></td>
|
||||
<td align="center"><a href="http://twitter.com/natterstefan"><img src="https://avatars2.githubusercontent.com/u/1043668?v=4" width="100px;" alt="Stefan Natter"/><br /><sub><b>Stefan Natter</b></sub></a><br /><a href="https://github.com/DylanPiercey/local-devices/commits?author=natterstefan" title="Code">💻</a> <a href="https://github.com/DylanPiercey/local-devices/commits?author=natterstefan" title="Tests">⚠️</a> <a href="https://github.com/DylanPiercey/local-devices/issues?q=author%3Anatterstefan" title="Bug reports">🐛</a> <a href="https://github.com/DylanPiercey/local-devices/commits?author=natterstefan" title="Documentation">📖</a> <a href="#ideas-natterstefan" title="Ideas, Planning, & Feedback">🤔</a></td>
|
||||
<td align="center"><a href="https://github.com/kounelios13"><img src="https://avatars3.githubusercontent.com/u/11466138?v=4" width="100px;" alt="kounelios13"/><br /><sub><b>kounelios13</b></sub></a><br /><a href="https://github.com/DylanPiercey/local-devices/issues?q=author%3Akounelios13" title="Bug reports">🐛</a> <a href="https://github.com/DylanPiercey/local-devices/commits?author=kounelios13" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://github.com/MarkusSuomi"><img src="https://avatars3.githubusercontent.com/u/5594334?v=4" width="100px;" alt="MarkusSuomi"/><br /><sub><b>MarkusSuomi</b></sub></a><br /><a href="https://github.com/DylanPiercey/local-devices/commits?author=MarkusSuomi" title="Code">💻</a></td>
|
||||
<td align="center"><a href="http://nolazybits.com"><img src="https://avatars1.githubusercontent.com/u/214998?v=4" width="100px;" alt="Xavier Martin"/><br /><sub><b>Xavier Martin</b></sub></a><br /><a href="https://github.com/DylanPiercey/local-devices/commits?author=nolazybits" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://me.howel52.com/"><img src="https://avatars0.githubusercontent.com/u/9854818?v=4" width="100px;" alt="howel52"/><br /><sub><b>howel52</b></sub></a><br /><a href="https://github.com/DylanPiercey/local-devices/commits?author=howel52" title="Code">💻</a> <a href="https://github.com/DylanPiercey/local-devices/issues?q=author%3Ahowel52" title="Bug reports">🐛</a></td>
|
||||
<td align="center"><a href="https://github.com/LucaSoldi"><img src="https://avatars0.githubusercontent.com/u/5584781?v=4" width="100px;" alt="LucaSoldi"/><br /><sub><b>LucaSoldi</b></sub></a><br /><a href="https://github.com/DylanPiercey/local-devices/commits?author=LucaSoldi" title="Code">💻</a> <a href="https://github.com/DylanPiercey/local-devices/issues?q=author%3ALucaSoldi" title="Bug reports">🐛</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/Miosame"><img src="https://avatars1.githubusercontent.com/u/8201077?v=4" width="100px;" alt="Miosame"/><br /><sub><b>Miosame</b></sub></a><br /><a href="https://github.com/DylanPiercey/local-devices/commits?author=Miosame" title="Code">💻</a> <a href="https://github.com/DylanPiercey/local-devices/commits?author=Miosame" title="Documentation">📖</a> <a href="#example-Miosame" title="Examples">💡</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- markdownlint-enable -->
|
||||
<!-- prettier-ignore-end -->
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
This project follows the [all-contributors][all-contributors] specification.
|
||||
Contributions of any kind are welcome!
|
||||
|
||||
### How to add Contributors
|
||||
|
||||
Contributors can be added with the [all-contributors cli](https://allcontributors.org/docs/en/cli/installation).
|
||||
The cli is already installed and can be [used like this](https://allcontributors.org/docs/en/bot/usage):
|
||||
|
||||
```bash
|
||||
yarn all-contributors add <username> <emoji-keys>
|
||||
```
|
||||
|
||||
## LICENCE
|
||||
|
||||
[MIT](LICENCE)
|
||||
|
||||
[package]: https://www.npmjs.com/package/local-devices
|
||||
[licence]: https://github.com/DylanPiercey/local-devices/blob/master/LICENCE
|
||||
[prs]: http://makeapullrequest.com
|
||||
[github-watch]: https://github.com/DylanPiercey/local-devices/watchers
|
||||
[github-star]: https://github.com/DylanPiercey/local-devices/stargazers
|
||||
[github-watch-badge]: https://img.shields.io/github/watchers/DylanPiercey/local-devices.svg?style=social
|
||||
[github-star-badge]: https://img.shields.io/github/stars/DylanPiercey/local-devices.svg?style=social
|
||||
[version-badge]: https://img.shields.io/npm/v/local-devices.svg?style=flat-square
|
||||
[license-badge]: https://img.shields.io/npm/l/local-devices.svg?style=flat-square
|
||||
[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
|
||||
[emojis]: https://github.com/kentcdodds/all-contributors#emoji-key
|
||||
[all-contributors]: https://github.com/kentcdodds/all-contributors
|
||||
|
||||
[build-badge]: https://travis-ci.org/DylanPiercey/local-devices.svg?branch=master
|
||||
[build]: https://travis-ci.org/DylanPiercey/local-devices
|
||||
[coverage-badge]: https://coveralls.io/repos/github/DylanPiercey/local-devices/badge.svg?branch=master
|
||||
[coverage]: https://coveralls.io/github/DylanPiercey/local-devices?branch=master
|
82
node_modules/local-devices/package.json
generated
vendored
Normal file
82
node_modules/local-devices/package.json
generated
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
{
|
||||
"name": "local-devices",
|
||||
"description": "Find devices connected to the current local network.",
|
||||
"version": "3.1.0",
|
||||
"author": "Dylan Piercey <pierceydylan@gmail.com>",
|
||||
"license": "MIT",
|
||||
"main": "src/index.js",
|
||||
"files": [
|
||||
"src"
|
||||
],
|
||||
"scripts": {
|
||||
"contributors:add": "all-contributors add",
|
||||
"contributors:generate": "all-contributors generate",
|
||||
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls",
|
||||
"lint": "standard --verbose | snazzy",
|
||||
"test": "jest",
|
||||
"pretest": "npm run lint",
|
||||
"watch-test": "jest --watch"
|
||||
},
|
||||
"types": "./src/index.d.ts",
|
||||
"dependencies": {
|
||||
"get-ip-range": "^2.1.0",
|
||||
"ip": "^1.1.5",
|
||||
"mz": "^2.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^24.0.19",
|
||||
"all-contributors-cli": "^6.9.3",
|
||||
"coveralls": "^3.0.7",
|
||||
"husky": "^3.0.9",
|
||||
"jest": "^24.9.0",
|
||||
"lint-staged": "^9.4.2",
|
||||
"snazzy": "^8.0.0",
|
||||
"standard": "^14.3.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.17"
|
||||
},
|
||||
"homepage": "https://github.com/DylanPiercey/local-devices",
|
||||
"bugs": "https://github.com/DylanPiercey/local-devices/issues",
|
||||
"keywords": [
|
||||
"arp",
|
||||
"devices",
|
||||
"ip",
|
||||
"local",
|
||||
"mac",
|
||||
"mac-address",
|
||||
"scan"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/DylanPiercey/local-devices"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "lint-staged",
|
||||
"pre-push": "npm test"
|
||||
}
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.js": [
|
||||
"npm run lint",
|
||||
"git update-index --again",
|
||||
"jest --findRelatedTests"
|
||||
]
|
||||
},
|
||||
"jest": {
|
||||
"setupFiles": [
|
||||
"./jest-setup.js"
|
||||
]
|
||||
},
|
||||
"standard": {
|
||||
"globals": [
|
||||
"jest",
|
||||
"describe",
|
||||
"beforeAll",
|
||||
"afterAll",
|
||||
"it",
|
||||
"expect"
|
||||
]
|
||||
}
|
||||
}
|
16
node_modules/local-devices/src/index.d.ts
generated
vendored
Normal file
16
node_modules/local-devices/src/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
declare module "local-devices" {
|
||||
|
||||
function findLocalDevices(address?: any): Promise<findLocalDevices.IDevice[]>;
|
||||
|
||||
namespace findLocalDevices
|
||||
{
|
||||
interface IDevice
|
||||
{
|
||||
name: string;
|
||||
ip: string;
|
||||
mac: string;
|
||||
}
|
||||
}
|
||||
|
||||
export = findLocalDevices;
|
||||
}
|
180
node_modules/local-devices/src/index.js
generated
vendored
Normal file
180
node_modules/local-devices/src/index.js
generated
vendored
Normal file
@ -0,0 +1,180 @@
|
||||
var ip = require('ip')
|
||||
var os = require('os')
|
||||
var net = require('net')
|
||||
var cp = require('mz/child_process')
|
||||
var getIPRange = require('get-ip-range')
|
||||
|
||||
var parseLinux = require('./parser/linux')
|
||||
var parseWin32 = require('./parser/win32')
|
||||
var parseRow = require('./parser')
|
||||
|
||||
var servers
|
||||
var lock = {}
|
||||
|
||||
const TEN_MEGA_BYTE = 1024 * 1024 * 10
|
||||
const ONE_MINUTE = 60 * 1000
|
||||
const options = {
|
||||
maxBuffer: TEN_MEGA_BYTE,
|
||||
timeout: ONE_MINUTE
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all local devices (ip and mac address) connectd to the current network.
|
||||
*/
|
||||
module.exports = function findLocalDevices (address) {
|
||||
var key = String(address)
|
||||
|
||||
if (isRange(address)) {
|
||||
try {
|
||||
servers = getIPRange(key)
|
||||
} catch (error) {
|
||||
// Note: currently doesn't throw the intended error message from the package maintainer
|
||||
// It will still be caught, PR here though: https://github.com/JoeScho/get-ip-range/pull/6
|
||||
return error
|
||||
}
|
||||
} else {
|
||||
servers = getServers()
|
||||
}
|
||||
|
||||
if (!lock[key]) {
|
||||
if (!address || isRange(key)) {
|
||||
lock[key] = pingServers().then(arpAll).then(unlock(key))
|
||||
} else {
|
||||
lock[key] = pingServer(address).then(arpOne).then(unlock(key))
|
||||
}
|
||||
}
|
||||
|
||||
return lock[key]
|
||||
}
|
||||
|
||||
function isRange (address) {
|
||||
return address && new RegExp('/|-').test(address)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current list of possible servers in the local networks.
|
||||
*/
|
||||
function getServers () {
|
||||
var interfaces = os.networkInterfaces()
|
||||
var result = []
|
||||
|
||||
for (var key in interfaces) {
|
||||
var addresses = interfaces[key]
|
||||
for (var i = addresses.length; i--;) {
|
||||
var address = addresses[i]
|
||||
if (address.family === 'IPv4' && !address.internal) {
|
||||
var subnet = ip.subnet(address.address, address.netmask)
|
||||
var current = ip.toLong(subnet.firstAddress)
|
||||
var last = ip.toLong(subnet.lastAddress) - 1
|
||||
while (current++ < last) result.push(ip.fromLong(current))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a ping to all servers to update the arp table.
|
||||
*/
|
||||
function pingServers () {
|
||||
return Promise.all(servers.map(pingServer))
|
||||
}
|
||||
|
||||
/**
|
||||
* Pings and individual server to update the arp table.
|
||||
*/
|
||||
function pingServer (address) {
|
||||
return new Promise(function (resolve) {
|
||||
var socket = new net.Socket()
|
||||
socket.setTimeout(1000, close)
|
||||
socket.connect(80, address, close)
|
||||
socket.once('error', close)
|
||||
|
||||
function close () {
|
||||
socket.destroy()
|
||||
resolve(address)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the arp table.
|
||||
*/
|
||||
function arpAll () {
|
||||
return cp.exec('arp -a', options).then(parseAll)
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses arp scan data into a useable collection.
|
||||
*/
|
||||
function parseAll (data) {
|
||||
if (!data || !data[0]) {
|
||||
return []
|
||||
}
|
||||
|
||||
if (process.platform.includes('linux')) {
|
||||
var rows = data[0].split('\n')
|
||||
return rows.map(function (row) {
|
||||
return parseLinux(row, servers)
|
||||
}).filter(Boolean)
|
||||
} else if (process.platform.includes('win32')) {
|
||||
var winRows = data[0].split('\n').splice(1)
|
||||
return winRows.map(function (row) {
|
||||
return parseWin32(row, servers)
|
||||
}).filter(Boolean)
|
||||
}
|
||||
|
||||
return data[0]
|
||||
.trim()
|
||||
.split('\n')
|
||||
.map(function (row) {
|
||||
return parseRow(row, servers)
|
||||
})
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the arp table for a single address.
|
||||
*/
|
||||
function arpOne (address) {
|
||||
if (!ip.isV4Format(address) && !ip.isV6Format(address)) {
|
||||
return Promise.reject(new Error('Invalid IP address provided.'))
|
||||
}
|
||||
|
||||
return cp.exec('arp -n ' + address, options).then(parseOne)
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a single row of arp data.
|
||||
*/
|
||||
function parseOne (data) {
|
||||
if (!data || !data[0]) {
|
||||
return
|
||||
}
|
||||
|
||||
if (process.platform.includes('linux')) {
|
||||
// ignore unresolved hosts (can happen when parseOne returns only one unresolved host)
|
||||
if (data[0].indexOf('no entry') >= 0) {
|
||||
return
|
||||
}
|
||||
|
||||
// remove first row (containing "headlines")
|
||||
var rows = data[0].split('\n').slice(1)[0]
|
||||
return parseLinux(rows, servers, true)
|
||||
} else if (process.platform.includes('win32')) {
|
||||
return // currently not supported
|
||||
}
|
||||
|
||||
return parseRow(data[0], servers)
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the current promise and unlocks (will ping servers again).
|
||||
*/
|
||||
function unlock (key) {
|
||||
return function (data) {
|
||||
lock[key] = null
|
||||
return data
|
||||
}
|
||||
}
|
38
node_modules/local-devices/src/parser/index.js
generated
vendored
Normal file
38
node_modules/local-devices/src/parser/index.js
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Parses each row in the arp table into { name, ip, mac }.
|
||||
*/
|
||||
module.exports = function parseRow (row, servers) {
|
||||
// Parse name.
|
||||
var nameStart = 0
|
||||
var nameEnd = row.indexOf('(') - 1
|
||||
var name = row.slice(nameStart, nameEnd)
|
||||
|
||||
// Parse ip.
|
||||
var ipStart = nameEnd + 2
|
||||
var ipEnd = row.indexOf(')', ipStart)
|
||||
var ipAddress = row.slice(ipStart, ipEnd)
|
||||
// Only resolve external ips.
|
||||
if (!~servers.indexOf(ipAddress)) {
|
||||
return
|
||||
}
|
||||
|
||||
// Parse mac
|
||||
var macStart = row.indexOf(' at ', ipEnd) + 4
|
||||
var macEnd = row.indexOf(' on ', macStart)
|
||||
var macAddress = row.slice(macStart, macEnd)
|
||||
// Ignore unresolved hosts.
|
||||
if (macAddress === '(incomplete)') {
|
||||
return
|
||||
}
|
||||
// Format for always 2 digits
|
||||
macAddress = macAddress
|
||||
.replace(/^.:/, '0$&')
|
||||
.replace(/:.(?=:|$)/g, ':0X$&')
|
||||
.replace(/X:/g, '')
|
||||
|
||||
return {
|
||||
name: name,
|
||||
ip: ipAddress,
|
||||
mac: macAddress
|
||||
}
|
||||
}
|
43
node_modules/local-devices/src/parser/linux.js
generated
vendored
Normal file
43
node_modules/local-devices/src/parser/linux.js
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Parses each row in the arp table into { name, ip, mac } on linux.
|
||||
*
|
||||
* partially inspired by https://github.com/goliatone/arpscan/blob/master/lib/arpscanner.js
|
||||
*/
|
||||
module.exports = function parseLinux (row, servers, parseOne) {
|
||||
var result = {}
|
||||
|
||||
// Ignore unresolved hosts.
|
||||
if (row === '' || row.indexOf('incomplete') >= 0) {
|
||||
return
|
||||
}
|
||||
|
||||
var chunks = row.split(' ').filter(Boolean)
|
||||
if (parseOne) {
|
||||
result = prepareOne(chunks)
|
||||
} else {
|
||||
result = prepareAll(chunks)
|
||||
}
|
||||
|
||||
// Only resolve external ips.
|
||||
if (!~servers.indexOf(result.ip)) {
|
||||
return
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function prepareOne (chunks) {
|
||||
return {
|
||||
name: '?', // a hostname is not provided on the raspberry pi (linux)
|
||||
ip: chunks[0],
|
||||
mac: chunks[2]
|
||||
}
|
||||
}
|
||||
|
||||
function prepareAll (chunks) {
|
||||
return {
|
||||
name: chunks[0],
|
||||
ip: chunks[1].match(/\((.*)\)/)[1],
|
||||
mac: chunks[3]
|
||||
}
|
||||
}
|
26
node_modules/local-devices/src/parser/win32.js
generated
vendored
Normal file
26
node_modules/local-devices/src/parser/win32.js
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Parses each row in the arp table into { name, ip, mac } on win32.
|
||||
*/
|
||||
module.exports = function parseRow (row, servers) {
|
||||
var chunks = row.split(/\s+/g).filter(function (el) { return el.length > 1 })
|
||||
|
||||
// Parse name.
|
||||
var ipAddress = chunks[0]
|
||||
// Only resolve external ips.
|
||||
if (!~servers.indexOf(ipAddress)) {
|
||||
return
|
||||
}
|
||||
|
||||
// Parse mac
|
||||
var macAddress = chunks[1].replace(/-/g, ':')
|
||||
// Ignore unresolved hosts.
|
||||
if (macAddress === '(incomplete)') {
|
||||
return
|
||||
}
|
||||
|
||||
return {
|
||||
name: '?', // unresolved
|
||||
ip: ipAddress,
|
||||
mac: macAddress
|
||||
}
|
||||
}
|
47
node_modules/lodash.find/LICENSE
generated
vendored
Normal file
47
node_modules/lodash.find/LICENSE
generated
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
Copyright jQuery Foundation and other contributors <https://jquery.org/>
|
||||
|
||||
Based on Underscore.js, copyright Jeremy Ashkenas,
|
||||
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
|
||||
|
||||
This software consists of voluntary contributions made by many
|
||||
individuals. For exact contribution history, see the revision history
|
||||
available at https://github.com/lodash/lodash
|
||||
|
||||
The following license applies to all parts of this software except as
|
||||
documented below:
|
||||
|
||||
====
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
====
|
||||
|
||||
Copyright and related rights for sample code are waived via CC0. Sample
|
||||
code is defined as all source code displayed within the prose of the
|
||||
documentation.
|
||||
|
||||
CC0: http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
====
|
||||
|
||||
Files located in the node_modules and vendor directories are externally
|
||||
maintained libraries used by this software which have their own
|
||||
licenses; we recommend you read them, as their terms may differ from the
|
||||
terms above.
|
18
node_modules/lodash.find/README.md
generated
vendored
Normal file
18
node_modules/lodash.find/README.md
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
# lodash.find v4.6.0
|
||||
|
||||
The [lodash](https://lodash.com/) method `_.find` exported as a [Node.js](https://nodejs.org/) module.
|
||||
|
||||
## Installation
|
||||
|
||||
Using npm:
|
||||
```bash
|
||||
$ {sudo -H} npm i -g npm
|
||||
$ npm i --save lodash.find
|
||||
```
|
||||
|
||||
In Node.js:
|
||||
```js
|
||||
var find = require('lodash.find');
|
||||
```
|
||||
|
||||
See the [documentation](https://lodash.com/docs#find) or [package source](https://github.com/lodash/lodash/blob/4.6.0-npm-packages/lodash.find) for more details.
|
2453
node_modules/lodash.find/index.js
generated
vendored
Normal file
2453
node_modules/lodash.find/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
17
node_modules/lodash.find/package.json
generated
vendored
Normal file
17
node_modules/lodash.find/package.json
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "lodash.find",
|
||||
"version": "4.6.0",
|
||||
"description": "The lodash method `_.find` exported as a module.",
|
||||
"homepage": "https://lodash.com/",
|
||||
"icon": "https://lodash.com/icon.svg",
|
||||
"license": "MIT",
|
||||
"keywords": "lodash-modularized, find",
|
||||
"author": "John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)",
|
||||
"contributors": [
|
||||
"John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)",
|
||||
"Blaine Bublitz <blaine.bublitz@gmail.com> (https://github.com/phated)",
|
||||
"Mathias Bynens <mathias@qiwi.be> (https://mathiasbynens.be/)"
|
||||
],
|
||||
"repository": "lodash/lodash",
|
||||
"scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" }
|
||||
}
|
47
node_modules/lodash.max/LICENSE
generated
vendored
Normal file
47
node_modules/lodash.max/LICENSE
generated
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
Copyright jQuery Foundation and other contributors <https://jquery.org/>
|
||||
|
||||
Based on Underscore.js, copyright Jeremy Ashkenas,
|
||||
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
|
||||
|
||||
This software consists of voluntary contributions made by many
|
||||
individuals. For exact contribution history, see the revision history
|
||||
available at https://github.com/lodash/lodash
|
||||
|
||||
The following license applies to all parts of this software except as
|
||||
documented below:
|
||||
|
||||
====
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
====
|
||||
|
||||
Copyright and related rights for sample code are waived via CC0. Sample
|
||||
code is defined as all source code displayed within the prose of the
|
||||
documentation.
|
||||
|
||||
CC0: http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
====
|
||||
|
||||
Files located in the node_modules and vendor directories are externally
|
||||
maintained libraries used by this software which have their own
|
||||
licenses; we recommend you read them, as their terms may differ from the
|
||||
terms above.
|
18
node_modules/lodash.max/README.md
generated
vendored
Normal file
18
node_modules/lodash.max/README.md
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
# lodash.max v4.0.1
|
||||
|
||||
The [lodash](https://lodash.com/) method `_.max` exported as a [Node.js](https://nodejs.org/) module.
|
||||
|
||||
## Installation
|
||||
|
||||
Using npm:
|
||||
```bash
|
||||
$ {sudo -H} npm i -g npm
|
||||
$ npm i --save lodash.max
|
||||
```
|
||||
|
||||
In Node.js:
|
||||
```js
|
||||
var max = require('lodash.max');
|
||||
```
|
||||
|
||||
See the [documentation](https://lodash.com/docs#max) or [package source](https://github.com/lodash/lodash/blob/4.0.1-npm-packages/lodash.max) for more details.
|
160
node_modules/lodash.max/index.js
generated
vendored
Normal file
160
node_modules/lodash.max/index.js
generated
vendored
Normal file
@ -0,0 +1,160 @@
|
||||
/**
|
||||
* lodash (Custom Build) <https://lodash.com/>
|
||||
* Build: `lodash modularize exports="npm" -o ./`
|
||||
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
|
||||
* Released under MIT license <https://lodash.com/license>
|
||||
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
||||
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
||||
*/
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var symbolTag = '[object Symbol]';
|
||||
|
||||
/** Used for built-in method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/**
|
||||
* Used to resolve the
|
||||
* [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
|
||||
* of values.
|
||||
*/
|
||||
var objectToString = objectProto.toString;
|
||||
|
||||
/**
|
||||
* The base implementation of methods like `_.max` and `_.min` which accepts a
|
||||
* `comparator` to determine the extremum value.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to iterate over.
|
||||
* @param {Function} iteratee The iteratee invoked per iteration.
|
||||
* @param {Function} comparator The comparator used to compare values.
|
||||
* @returns {*} Returns the extremum value.
|
||||
*/
|
||||
function baseExtremum(array, iteratee, comparator) {
|
||||
var index = -1,
|
||||
length = array.length;
|
||||
|
||||
while (++index < length) {
|
||||
var value = array[index],
|
||||
current = iteratee(value);
|
||||
|
||||
if (current != null && (computed === undefined
|
||||
? (current === current && !isSymbol(current))
|
||||
: comparator(current, computed)
|
||||
)) {
|
||||
var computed = current,
|
||||
result = value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* The base implementation of `_.gt` which doesn't coerce arguments to numbers.
|
||||
*
|
||||
* @private
|
||||
* @param {*} value The value to compare.
|
||||
* @param {*} other The other value to compare.
|
||||
* @returns {boolean} Returns `true` if `value` is greater than `other`,
|
||||
* else `false`.
|
||||
*/
|
||||
function baseGt(value, other) {
|
||||
return value > other;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if `value` is object-like. A value is object-like if it's not `null`
|
||||
* and has a `typeof` result of "object".
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 4.0.0
|
||||
* @category Lang
|
||||
* @param {*} value The value to check.
|
||||
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
||||
* @example
|
||||
*
|
||||
* _.isObjectLike({});
|
||||
* // => true
|
||||
*
|
||||
* _.isObjectLike([1, 2, 3]);
|
||||
* // => true
|
||||
*
|
||||
* _.isObjectLike(_.noop);
|
||||
* // => false
|
||||
*
|
||||
* _.isObjectLike(null);
|
||||
* // => false
|
||||
*/
|
||||
function isObjectLike(value) {
|
||||
return !!value && typeof value == 'object';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if `value` is classified as a `Symbol` primitive or object.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 4.0.0
|
||||
* @category Lang
|
||||
* @param {*} value The value to check.
|
||||
* @returns {boolean} Returns `true` if `value` is correctly classified,
|
||||
* else `false`.
|
||||
* @example
|
||||
*
|
||||
* _.isSymbol(Symbol.iterator);
|
||||
* // => true
|
||||
*
|
||||
* _.isSymbol('abc');
|
||||
* // => false
|
||||
*/
|
||||
function isSymbol(value) {
|
||||
return typeof value == 'symbol' ||
|
||||
(isObjectLike(value) && objectToString.call(value) == symbolTag);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the first argument given to it.
|
||||
*
|
||||
* @static
|
||||
* @since 0.1.0
|
||||
* @memberOf _
|
||||
* @category Util
|
||||
* @param {*} value Any value.
|
||||
* @returns {*} Returns `value`.
|
||||
* @example
|
||||
*
|
||||
* var object = { 'user': 'fred' };
|
||||
*
|
||||
* _.identity(object) === object;
|
||||
* // => true
|
||||
*/
|
||||
function identity(value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the maximum value of `array`. If `array` is empty or falsey,
|
||||
* `undefined` is returned.
|
||||
*
|
||||
* @static
|
||||
* @since 0.1.0
|
||||
* @memberOf _
|
||||
* @category Math
|
||||
* @param {Array} array The array to iterate over.
|
||||
* @returns {*} Returns the maximum value.
|
||||
* @example
|
||||
*
|
||||
* _.max([4, 2, 8, 6]);
|
||||
* // => 8
|
||||
*
|
||||
* _.max([]);
|
||||
* // => undefined
|
||||
*/
|
||||
function max(array) {
|
||||
return (array && array.length)
|
||||
? baseExtremum(array, identity, baseGt)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
module.exports = max;
|
17
node_modules/lodash.max/package.json
generated
vendored
Normal file
17
node_modules/lodash.max/package.json
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "lodash.max",
|
||||
"version": "4.0.1",
|
||||
"description": "The lodash method `_.max` exported as a module.",
|
||||
"homepage": "https://lodash.com/",
|
||||
"icon": "https://lodash.com/icon.svg",
|
||||
"license": "MIT",
|
||||
"keywords": "lodash-modularized, max",
|
||||
"author": "John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)",
|
||||
"contributors": [
|
||||
"John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)",
|
||||
"Blaine Bublitz <blaine.bublitz@gmail.com> (https://github.com/phated)",
|
||||
"Mathias Bynens <mathias@qiwi.be> (https://mathiasbynens.be/)"
|
||||
],
|
||||
"repository": "lodash/lodash",
|
||||
"scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" }
|
||||
}
|
47
node_modules/lodash.merge/LICENSE
generated
vendored
Normal file
47
node_modules/lodash.merge/LICENSE
generated
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
|
||||
|
||||
Based on Underscore.js, copyright Jeremy Ashkenas,
|
||||
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
|
||||
|
||||
This software consists of voluntary contributions made by many
|
||||
individuals. For exact contribution history, see the revision history
|
||||
available at https://github.com/lodash/lodash
|
||||
|
||||
The following license applies to all parts of this software except as
|
||||
documented below:
|
||||
|
||||
====
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
====
|
||||
|
||||
Copyright and related rights for sample code are waived via CC0. Sample
|
||||
code is defined as all source code displayed within the prose of the
|
||||
documentation.
|
||||
|
||||
CC0: http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
====
|
||||
|
||||
Files located in the node_modules and vendor directories are externally
|
||||
maintained libraries used by this software which have their own
|
||||
licenses; we recommend you read them, as their terms may differ from the
|
||||
terms above.
|
18
node_modules/lodash.merge/README.md
generated
vendored
Normal file
18
node_modules/lodash.merge/README.md
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
# lodash.merge v4.6.2
|
||||
|
||||
The [Lodash](https://lodash.com/) method `_.merge` exported as a [Node.js](https://nodejs.org/) module.
|
||||
|
||||
## Installation
|
||||
|
||||
Using npm:
|
||||
```bash
|
||||
$ {sudo -H} npm i -g npm
|
||||
$ npm i --save lodash.merge
|
||||
```
|
||||
|
||||
In Node.js:
|
||||
```js
|
||||
var merge = require('lodash.merge');
|
||||
```
|
||||
|
||||
See the [documentation](https://lodash.com/docs#merge) or [package source](https://github.com/lodash/lodash/blob/4.6.2-npm-packages/lodash.merge) for more details.
|
1977
node_modules/lodash.merge/index.js
generated
vendored
Normal file
1977
node_modules/lodash.merge/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
16
node_modules/lodash.merge/package.json
generated
vendored
Normal file
16
node_modules/lodash.merge/package.json
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "lodash.merge",
|
||||
"version": "4.6.2",
|
||||
"description": "The Lodash method `_.merge` exported as a module.",
|
||||
"homepage": "https://lodash.com/",
|
||||
"icon": "https://lodash.com/icon.svg",
|
||||
"license": "MIT",
|
||||
"keywords": "lodash-modularized, merge",
|
||||
"author": "John-David Dalton <john.david.dalton@gmail.com>",
|
||||
"contributors": [
|
||||
"John-David Dalton <john.david.dalton@gmail.com>",
|
||||
"Mathias Bynens <mathias@qiwi.be>"
|
||||
],
|
||||
"repository": "lodash/lodash",
|
||||
"scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" }
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user