前端代码
This commit is contained in:
39
node_modules/portscanner/.circleci/config.yml
generated
vendored
Normal file
39
node_modules/portscanner/.circleci/config.yml
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
# Javascript Node CircleCI 2.0 configuration file
|
||||
#
|
||||
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
|
||||
#
|
||||
version: 2
|
||||
jobs:
|
||||
build:
|
||||
docker:
|
||||
# specify the version you desire here
|
||||
- image: circleci/node:7.10
|
||||
|
||||
# Specify service dependencies here if necessary
|
||||
# CircleCI maintains a library of pre-built images
|
||||
# documented at https://circleci.com/docs/2.0/circleci-images/
|
||||
# - image: circleci/mongo:3.4.4
|
||||
|
||||
working_directory: ~/repo
|
||||
|
||||
steps:
|
||||
- checkout
|
||||
|
||||
# Download and cache dependencies
|
||||
- restore_cache:
|
||||
keys:
|
||||
- v1-dependencies-{{ checksum "package.json" }}
|
||||
# fallback to using the latest cache if no exact match is found
|
||||
- v1-dependencies-
|
||||
|
||||
- run: npm install
|
||||
|
||||
- save_cache:
|
||||
paths:
|
||||
- node_modules
|
||||
key: v1-dependencies-{{ checksum "package.json" }}
|
||||
|
||||
# run tests!
|
||||
- run: npm test
|
||||
|
||||
|
103
node_modules/portscanner/CHANGELOG.md
generated
vendored
Normal file
103
node_modules/portscanner/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,103 @@
|
||||
# 2.1.0
|
||||
|
||||
## New
|
||||
|
||||
* [[`ed4682bd3c`](https://github.com/baalexander/node-portscanner/commit/ed4682bd3c)] - Accept ports as strings (laggingreflex)
|
||||
|
||||
# 2.0.0
|
||||
|
||||
## Breaking Changes
|
||||
|
||||
* Ports must be numbers. Some of the new changes are based on the assumption that ports must be numbers.
|
||||
|
||||
## New
|
||||
|
||||
* [[`84db394996`](https://github.com/baalexander/node-portscanner/commit/84db394996)] - promise support (laggingreflex)
|
||||
* [[`3b90e2ca74`](https://github.com/baalexander/node-portscanner/commit/3b90e2ca74)] - Improve arguments parsing (laggingreflex)
|
||||
* [[`eb345da68c`](https://github.com/baalexander/node-portscanner/commit/eb345da68c)] - Make host parameter optional (Maciej Dudzinski)
|
||||
* [[`2ed556b159`](https://github.com/baalexander/node-portscanner/commit/2ed556b159)] [[`99483dc28e`](https://github.com/baalexander/node-portscanner/commit/99483dc28e)] [#26](https://github.com/baalexander/node-portscanner/issues/26) - Add support for checking array of ports instead of range (Maciej Dudzinski)
|
||||
|
||||
## Fixes
|
||||
|
||||
* [[`da8ff250bd`](https://github.com/baalexander/node-portscanner/commit/da8ff250bd)] [#23](https://github.com/baalexander/node-portscanner/issues/23) - handle ports range provided in reverse order (laggingreflex)
|
||||
* [[`4c7a88436f`](https://github.com/baalexander/node-portscanner/commit/4c7a88436f)] - Update async module for use this module in strict mode (Luca Pau)
|
||||
* [[`04fea5dd4d`](https://github.com/baalexander/node-portscanner/commit/04fea5dd4d)] - Preserve error message from socket's error event (Jan Melcher)
|
||||
|
||||
## Misc
|
||||
|
||||
* [[`0beeca8cbd`](https://github.com/baalexander/node-portscanner/commit/0beeca8cbd)] - Implement JavaScript Standard Style Guide (laggingreflex)
|
||||
* [[`da1ce58319`](https://github.com/baalexander/node-portscanner/commit/da1ce58319)] - more tests for different argument signatures (laggingreflex)
|
||||
* [[`9fdbdc38d7`](https://github.com/baalexander/node-portscanner/commit/9fdbdc38d7)] - Add basic unit tests with Ava runner (Maciej Dudzinski)
|
||||
|
||||
# 1.2.0
|
||||
|
||||
Some recent changes in 1.1.0 [[`3b90e2ca74`](https://github.com/baalexander/node-portscanner/commit/3b90e2ca74)] [[`eb345da68c`](https://github.com/baalexander/node-portscanner/commit/eb345da68c)] were based on the assumption that the ports would always be of the type numbers. This broke portscanner in some cases [#49](https://github.com/baalexander/node-portscanner/issues/49) [#50](https://github.com/baalexander/node-portscanner/issues/50). All changes were reverted back to 1.0.0 and only some very critical fixes [[`4c7a88436f`](https://github.com/baalexander/node-portscanner/commit/4c7a88436f)] [[`04fea5dd4d`](https://github.com/baalexander/node-portscanner/commit/04fea5dd4d)] were applied to this version.
|
||||
|
||||
|
||||
## Fixes
|
||||
|
||||
* [[`4c7a88436f`](https://github.com/baalexander/node-portscanner/commit/4c7a88436f)] - Update async module for use this module in strict mode (Luca Pau)
|
||||
* [[`04fea5dd4d`](https://github.com/baalexander/node-portscanner/commit/04fea5dd4d)] - Preserve error message from socket's error event (Jan Melcher)
|
||||
|
||||
## Misc
|
||||
|
||||
* [[`69c648c740`](https://github.com/baalexander/node-portscanner/commit/69c648c740)] - tests - ports as strings (laggingreflex)
|
||||
* [[`9fdbdc38d7`](https://github.com/baalexander/node-portscanner/commit/9fdbdc38d7)] - Add basic unit tests with Ava runner (Maciej Dudzinski)
|
||||
|
||||
|
||||
# 1.1.1
|
||||
|
||||
Reverted to 1.0.0
|
||||
|
||||
# 1.1.0
|
||||
|
||||
Some breaking changes were introduced in this version which have since been reverted in 1.1.1.
|
||||
|
||||
Please update to either 1.1.1 or 2.0.0.
|
||||
|
||||
# 1.0.0
|
||||
|
||||
* [[`2463e64a0a`](https://github.com/baalexander/node-portscanner/commit/2463e64a0a)] - 1.0.0 (Sean Massa)
|
||||
* [[`21aa98b632`](https://github.com/baalexander/node-portscanner/commit/21aa98b632)] - update readme (Sean Massa)
|
||||
* [[`5fe4ab4a69`](https://github.com/baalexander/node-portscanner/commit/5fe4ab4a69)] - Merge pull request #21 from jdwilliams15/master (Sean Massa)
|
||||
* [[`725afef7b4`](https://github.com/baalexander/node-portscanner/commit/725afef7b4)] - fix indent (jdwilliams15)
|
||||
* [[`053b56e455`](https://github.com/baalexander/node-portscanner/commit/053b56e455)] - fixed indentation (jdwilliams15)
|
||||
* [[`b1dd496633`](https://github.com/baalexander/node-portscanner/commit/b1dd496633)] - Changed socket error handler to handle 'ECONNREFUSED'. In event of ECONNREFUSED the port is available (jdwilliams15)
|
||||
* [[`512cfdbf78`](https://github.com/baalexander/node-portscanner/commit/512cfdbf78)] - 0.2.3 (Sean Massa)
|
||||
* [[`5526b8b4eb`](https://github.com/baalexander/node-portscanner/commit/5526b8b4eb)] - Merge pull request #19 from thomseddon/fix-end (Sean Massa)
|
||||
* [[`a854ec6bd6`](https://github.com/baalexander/node-portscanner/commit/a854ec6bd6)] - Use socket.destroy() not socket.end() on successful connection (Thom Seddon)
|
||||
* [[`c747ffa9de`](https://github.com/baalexander/node-portscanner/commit/c747ffa9de)] - 0.2.2 (Sean Massa)
|
||||
* [[`4a1f8f811b`](https://github.com/baalexander/node-portscanner/commit/4a1f8f811b)] - Merge pull request #16 from baalexander/fix-port-finding (Sean Massa)
|
||||
* [[`ff51ebe871`](https://github.com/baalexander/node-portscanner/commit/ff51ebe871)] - fix port reporting (Sean Massa)
|
||||
* [[`e9070e85ca`](https://github.com/baalexander/node-portscanner/commit/e9070e85ca)] - 0.2.1 (Sean Massa)
|
||||
* [[`809b7760ad`](https://github.com/baalexander/node-portscanner/commit/809b7760ad)] - 0.2.0 (Sean Massa)
|
||||
* [[`87f35e5b87`](https://github.com/baalexander/node-portscanner/commit/87f35e5b87)] - Merge pull request #14 from baalexander/localhost-127.0.0.1 (Sean Massa)
|
||||
* [[`0b72b83cab`](https://github.com/baalexander/node-portscanner/commit/0b72b83cab)] - switch out localhost for 127.0.0.1 (Sean Massa)
|
||||
* [[`4407d6f701`](https://github.com/baalexander/node-portscanner/commit/4407d6f701)] - Merge pull request #13 from skilesare/master (Sean Massa)
|
||||
* [[`3ed682ad7a`](https://github.com/baalexander/node-portscanner/commit/3ed682ad7a)] - Update portscanner.js (skilesare)
|
||||
* [[`c1544a1bb3`](https://github.com/baalexander/node-portscanner/commit/c1544a1bb3)] - Update portscanner.js (skilesare)
|
||||
* [[`d3b029c384`](https://github.com/baalexander/node-portscanner/commit/d3b029c384)] - Adds @EndangeredMassa as a package maintainer. (Brandon Alexander)
|
||||
* [[`8f5559b1fe`](https://github.com/baalexander/node-portscanner/commit/8f5559b1fe)] - Merge pull request #7 from EndangeredMassa/smassa/timeout (Brandon Alexander)
|
||||
* [[`16d0db3944`](https://github.com/baalexander/node-portscanner/commit/16d0db3944)] - added options param to checkPortStatus; supports host and timeout (Sean Massa)
|
||||
* [[`b8acb18a08`](https://github.com/baalexander/node-portscanner/commit/b8acb18a08)] - exposed errors for checkPortStatus (Sean Massa)
|
||||
* [[`381769162d`](https://github.com/baalexander/node-portscanner/commit/381769162d)] - Updates version to 0.1.3. (Brandon Alexander)
|
||||
* [[`38cb922d1c`](https://github.com/baalexander/node-portscanner/commit/38cb922d1c)] - Uses callback in listen() instead of a timeout. (Brandon Alexander)
|
||||
* [[`aefd8ccad1`](https://github.com/baalexander/node-portscanner/commit/aefd8ccad1)] - Merge pull request #4 from DennisKehrig/master (Brandon Alexander)
|
||||
* [[`5b58f03421`](https://github.com/baalexander/node-portscanner/commit/5b58f03421)] - Call socket.destroy() on timeout (Dennis Kehrig)
|
||||
* [[`45028c6e3e`](https://github.com/baalexander/node-portscanner/commit/45028c6e3e)] - Updates version to 0.1.2. (Brandon Alexander)
|
||||
* [[`a60a248a2a`](https://github.com/baalexander/node-portscanner/commit/a60a248a2a)] - Fixes multiple callbacks when checking port status. (Brandon Alexander)
|
||||
* [[`19a8c1df2c`](https://github.com/baalexander/node-portscanner/commit/19a8c1df2c)] - Updates to v0.1.1. (Brandon Alexander)
|
||||
* [[`c81ae8d6e4`](https://github.com/baalexander/node-portscanner/commit/c81ae8d6e4)] - Checks range of ports one at a time. (Brandon Alexander)
|
||||
* [[`fe9726773d`](https://github.com/baalexander/node-portscanner/commit/fe9726773d)] - Only returns status of a port after connection closed. (Brandon Alexander)
|
||||
* [[`af6c474f38`](https://github.com/baalexander/node-portscanner/commit/af6c474f38)] - Ignores example and test directories in NPM. (Brandon Alexander)
|
||||
* [[`78be727cb4`](https://github.com/baalexander/node-portscanner/commit/78be727cb4)] - Initial release to NPM. (Brandon Alexander)
|
||||
* [[`cc71a028cb`](https://github.com/baalexander/node-portscanner/commit/cc71a028cb)] - Renames port finding functions for clarity. (Brandon Alexander)
|
||||
* [[`bb0356a82e`](https://github.com/baalexander/node-portscanner/commit/bb0356a82e)] - Quits scanning ports when a matching port has been found. (Brandon Alexander)
|
||||
* [[`24224b8148`](https://github.com/baalexander/node-portscanner/commit/24224b8148)] - Destroys the socket on error instead of end. (Brandon Alexander)
|
||||
* [[`e2c4448293`](https://github.com/baalexander/node-portscanner/commit/e2c4448293)] - Updates README since not yet ready for NPM. (Brandon Alexander)
|
||||
* [[`5cca315f8b`](https://github.com/baalexander/node-portscanner/commit/5cca315f8b)] - Packages up port scanner for NPM. (Brandon Alexander)
|
||||
* [[`8c1f11e76c`](https://github.com/baalexander/node-portscanner/commit/8c1f11e76c)] - Adds JSDocs and updates example code. (Brandon Alexander)
|
||||
* [[`4b432ba950`](https://github.com/baalexander/node-portscanner/commit/4b432ba950)] - Set max port range to 65535. (Brandon Alexander)
|
||||
* [[`3a78761e4f`](https://github.com/baalexander/node-portscanner/commit/3a78761e4f)] - Adds README and MIT license. (Brandon Alexander)
|
||||
* [[`e232efc85f`](https://github.com/baalexander/node-portscanner/commit/e232efc85f)] - Checks a range of ports for first open or closed port. (Brandon Alexander)
|
||||
* [[`8568c23e7c`](https://github.com/baalexander/node-portscanner/commit/8568c23e7c)] - Initial commit checks status of a specified port. (Brandon Alexander)
|
23
node_modules/portscanner/LICENSE
generated
vendored
Normal file
23
node_modules/portscanner/LICENSE
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
Copyright (c) 2011 Brandon Ace Alexander
|
||||
|
||||
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.
|
||||
|
79
node_modules/portscanner/README.md
generated
vendored
Normal file
79
node_modules/portscanner/README.md
generated
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
# portscanner
|
||||
|
||||
[](https://www.npmjs.com/package/portscanner)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
The portscanner module is
|
||||
an asynchronous JavaScript port scanner for Node.js.
|
||||
|
||||
Portscanner can check a port,
|
||||
or range of ports,
|
||||
for 'open' or 'closed' statuses.
|
||||
|
||||
[Looking for maintainer](https://github.com/baalexander/node-portscanner/issues/25)!
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm install portscanner
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
A brief example:
|
||||
|
||||
```javascript
|
||||
var portscanner = require('portscanner')
|
||||
|
||||
// Checks the status of a single port
|
||||
portscanner.checkPortStatus(3000, '127.0.0.1', function(error, status) {
|
||||
// Status is 'open' if currently in use or 'closed' if available
|
||||
console.log(status)
|
||||
})
|
||||
|
||||
// Find the first available port. Asynchronously checks, so first port
|
||||
// determined as available is returned.
|
||||
portscanner.findAPortNotInUse(3000, 3010, '127.0.0.1', function(error, port) {
|
||||
console.log('AVAILABLE PORT AT: ' + port)
|
||||
})
|
||||
|
||||
// Find the first port in use or blocked. Asynchronously checks, so first port
|
||||
// to respond is returned.
|
||||
portscanner.findAPortInUse(3000, 3010, '127.0.0.1', function(error, port) {
|
||||
console.log('PORT IN USE AT: ' + port)
|
||||
})
|
||||
|
||||
// You can also pass array of ports to check
|
||||
portscanner.findAPortInUse([3000, 3005, 3006], '127.0.0.1', function(error, port) {
|
||||
console.log('PORT IN USE AT: ' + port)
|
||||
})
|
||||
|
||||
// And skip host param. Default is '127.0.0.1'
|
||||
portscanner.findAPortNotInUse(3000, 4000, function(error, port) {
|
||||
console.log('PORT IN USE AT: ' + port)
|
||||
})
|
||||
|
||||
// And use promises
|
||||
portscanner.findAPortNotInUse(3000, 4000).then(function(port) {
|
||||
console.log('PORT IN USE AT: ' + port)
|
||||
})
|
||||
```
|
||||
|
||||
The example directory contains a more detailed example.
|
||||
|
||||
## Test
|
||||
|
||||
```sh
|
||||
npm test
|
||||
```
|
||||
|
||||
## Future
|
||||
|
||||
Please create issues or pull requests
|
||||
for port scanning related features
|
||||
you'd like to see included.
|
||||
|
||||
## License (MIT)
|
||||
|
||||
[MIT](LICENSE)
|
||||
|
251
node_modules/portscanner/lib/portscanner.js
generated
vendored
Normal file
251
node_modules/portscanner/lib/portscanner.js
generated
vendored
Normal file
@ -0,0 +1,251 @@
|
||||
var net = require('net')
|
||||
var Socket = net.Socket
|
||||
var async = require('async')
|
||||
var isNumberLike = require('is-number-like')
|
||||
var promisify = require('./promisify')
|
||||
|
||||
/**
|
||||
* Finds the first port with a status of 'open', implying the port is in use and
|
||||
* there is likely a service listening on it.
|
||||
*/
|
||||
/**
|
||||
* @param {Number} startPort - Port to begin status check on (inclusive).
|
||||
* @param {Number} [endPort=65535] - Last port to check status on (inclusive).
|
||||
* @param {String} [host='127.0.0.1'] - Host of where to scan.
|
||||
* @param {findPortCallback} [callback] - Function to call back with error or results.
|
||||
* @returns {Promise}
|
||||
* @example
|
||||
* // scans through 3000 to 3002 (inclusive)
|
||||
* portscanner.findAPortInUse(3000, 3002, '127.0.0.1', console.log)
|
||||
* // returns a promise in the absence of a callback
|
||||
* portscanner.findAPortInUse(3000, 3002, '127.0.0.1').then(console.log)
|
||||
* @example
|
||||
* // scans through 3000 to 65535 on '127.0.0.1'
|
||||
* portscanner.findAPortInUse(3000, console.log)
|
||||
*/
|
||||
/**
|
||||
* @param {Array} postList - Array of ports to check status on.
|
||||
* @param {String} [host='127.0.0.1'] - Host of where to scan.
|
||||
* @param {findPortCallback} [callback] - Function to call back with error or results.
|
||||
* @returns {Promise}
|
||||
* @example
|
||||
* // scans 3000 and 3002 only, not 3001.
|
||||
* portscanner.findAPortInUse([3000, 3002], console.log)
|
||||
*/
|
||||
function findAPortInUse () {
|
||||
var params = [].slice.call(arguments)
|
||||
params.unshift('open')
|
||||
return findAPortWithStatus.apply(null, params)
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the first port with a status of 'closed', implying the port is not in
|
||||
* use. Accepts identical parameters as {@link findAPortInUse}
|
||||
*/
|
||||
function findAPortNotInUse () {
|
||||
var params = [].slice.call(arguments)
|
||||
params.unshift('closed')
|
||||
return findAPortWithStatus.apply(null, params)
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the status of an individual port.
|
||||
*/
|
||||
/**
|
||||
* @param {Number} port - Port to check status on.
|
||||
* @param {String} [host='127.0.0.1'] - Host of where to scan.
|
||||
* @param {checkPortCallback} [callback] - Function to call back with error or results.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
/**
|
||||
* @param {Number} port - Port to check status on.
|
||||
* @param {Object} [opts={}] - Options object.
|
||||
* @param {String} [opts.host='127.0.0.1'] - Host of where to scan.
|
||||
* @param {Number} [opts.timeout=400] - Connection timeout in ms.
|
||||
* @param {checkPortCallback} [callback] - Function to call back with error or results.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
function checkPortStatus (port) {
|
||||
var args, host, opts, callback
|
||||
|
||||
args = [].slice.call(arguments, 1)
|
||||
|
||||
if (typeof args[0] === 'string') {
|
||||
host = args[0]
|
||||
} else if (typeof args[0] === 'object') {
|
||||
opts = args[0]
|
||||
} else if (typeof args[0] === 'function') {
|
||||
callback = args[0]
|
||||
}
|
||||
|
||||
if (typeof args[1] === 'object') {
|
||||
opts = args[1]
|
||||
} else if (typeof args[1] === 'function') {
|
||||
callback = args[1]
|
||||
}
|
||||
|
||||
if (typeof args[2] === 'function') {
|
||||
callback = args[2]
|
||||
}
|
||||
|
||||
if (!callback) return promisify(checkPortStatus, arguments)
|
||||
|
||||
opts = opts || {}
|
||||
|
||||
host = host || opts.host || '127.0.0.1'
|
||||
|
||||
var timeout = opts.timeout || 400
|
||||
var connectionRefused = false
|
||||
|
||||
var socket = new Socket()
|
||||
var status = null
|
||||
var error = null
|
||||
|
||||
// Socket connection established, port is open
|
||||
socket.on('connect', function () {
|
||||
status = 'open'
|
||||
socket.destroy()
|
||||
})
|
||||
|
||||
// If no response, assume port is not listening
|
||||
socket.setTimeout(timeout)
|
||||
socket.on('timeout', function () {
|
||||
status = 'closed'
|
||||
error = new Error('Timeout (' + timeout + 'ms) occurred waiting for ' + host + ':' + port + ' to be available')
|
||||
socket.destroy()
|
||||
})
|
||||
|
||||
// Assuming the port is not open if an error. May need to refine based on
|
||||
// exception
|
||||
socket.on('error', function (exception) {
|
||||
if (exception.code !== 'ECONNREFUSED') {
|
||||
error = exception
|
||||
} else {
|
||||
connectionRefused = true
|
||||
}
|
||||
status = 'closed'
|
||||
})
|
||||
|
||||
// Return after the socket has closed
|
||||
socket.on('close', function (exception) {
|
||||
if (exception && !connectionRefused) { error = error || exception } else { error = null }
|
||||
callback(error, status)
|
||||
})
|
||||
|
||||
socket.connect(port, host)
|
||||
}
|
||||
/**
|
||||
* Callback for {@link checkPortStatus}
|
||||
* @callback checkPortCallback
|
||||
* @param {Error|null} error - Any error that occurred while port scanning, or null.
|
||||
* @param {String} status - Status: 'open' if the port is in use, 'closed' if the port is available.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Internal helper function used by {@link findAPortInUse} and {@link findAPortNotInUse}
|
||||
* to find a port from a range or a list with a specific status.
|
||||
*/
|
||||
/**
|
||||
* @param {String} status - Status to check.
|
||||
* @param {...params} params - Params as passed exactly to {@link findAPortInUse} and {@link findAPortNotInUse}.
|
||||
*/
|
||||
function findAPortWithStatus (status) {
|
||||
var params, startPort, endPort, portList, host, opts, callback
|
||||
|
||||
params = [].slice.call(arguments, 1)
|
||||
|
||||
if (params[0] instanceof Array) {
|
||||
portList = params[0]
|
||||
} else if (isNumberLike(params[0])) {
|
||||
startPort = parseInt(params[0], 10)
|
||||
}
|
||||
|
||||
if (typeof params[1] === 'function') {
|
||||
callback = params[1]
|
||||
} else if (typeof params[1] === 'string') {
|
||||
host = params[1]
|
||||
} else if (typeof params[1] === 'object') {
|
||||
opts = params[1]
|
||||
} else if (isNumberLike(params[1])) {
|
||||
endPort = parseInt(params[1], 10)
|
||||
}
|
||||
|
||||
if (typeof params[2] === 'string') {
|
||||
host = params[2]
|
||||
} else if (typeof params[2] === 'object') {
|
||||
opts = params[2]
|
||||
} else if (typeof params[2] === 'function') {
|
||||
callback = params[2]
|
||||
}
|
||||
|
||||
if (typeof params[3] === 'function') {
|
||||
callback = params[3]
|
||||
}
|
||||
|
||||
if (!callback) return promisify(findAPortWithStatus, arguments)
|
||||
|
||||
opts = opts || {}
|
||||
|
||||
host = host || opts.host
|
||||
|
||||
if (startPort && endPort && endPort < startPort) {
|
||||
// WARNING: endPort less than startPort. Using endPort as startPort & vice versa.
|
||||
var tempStartPort = startPort
|
||||
startPort = endPort
|
||||
endPort = tempStartPort
|
||||
}
|
||||
|
||||
endPort = endPort || 65535
|
||||
|
||||
var foundPort = false
|
||||
var numberOfPortsChecked = 0
|
||||
var port = portList ? portList[0] : startPort
|
||||
|
||||
// Returns true if a port with matching status has been found or if checked
|
||||
// the entire range of ports
|
||||
var hasFoundPort = function () {
|
||||
return foundPort || numberOfPortsChecked === (portList ? portList.length : endPort - startPort + 1)
|
||||
}
|
||||
|
||||
// Checks the status of the port
|
||||
var checkNextPort = function (callback) {
|
||||
checkPortStatus(port, host, opts, function (error, statusOfPort) {
|
||||
numberOfPortsChecked++
|
||||
if (statusOfPort === status) {
|
||||
foundPort = true
|
||||
callback(error)
|
||||
} else {
|
||||
port = portList ? portList[numberOfPortsChecked] : port + 1
|
||||
callback(null)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Check the status of each port until one with a matching status has been
|
||||
// found or the range of ports has been exhausted
|
||||
async.until(hasFoundPort, checkNextPort, function (error) {
|
||||
if (error) {
|
||||
callback(error, port)
|
||||
} else if (foundPort) {
|
||||
callback(null, port)
|
||||
} else {
|
||||
callback(null, false)
|
||||
}
|
||||
})
|
||||
}
|
||||
/**
|
||||
* Callback for {@link findAPortWithStatus}, and by that extension, for {@link findAPortInUse} and {@link findAPortNotInUse}.
|
||||
* @callback findPortCallback
|
||||
* @param {Error|null} error - Any error that occurred while port scanning, or null.
|
||||
* @param {Number|Boolean} port - The first open port found. Note, this is the first port that returns status as 'open', not necessarily the first open port checked. If no open port is found, the value is false.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @exports portscanner
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
findAPortInUse: findAPortInUse,
|
||||
findAPortNotInUse: findAPortNotInUse,
|
||||
checkPortStatus: checkPortStatus
|
||||
}
|
19
node_modules/portscanner/lib/promisify.js
generated
vendored
Normal file
19
node_modules/portscanner/lib/promisify.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
module.exports = promisify
|
||||
|
||||
function promisify (fn, args) {
|
||||
if (typeof Promise === 'undefined') {
|
||||
throw new Error('Please run in a Promise supported environment or provide a callback')
|
||||
}
|
||||
return new Promise(function (resolve, reject) {
|
||||
args = [].slice.call(args).concat([callback])
|
||||
fn.apply(null, args)
|
||||
|
||||
function callback (error, port) {
|
||||
if (error || port === false) {
|
||||
reject(error || new Error('No open port found'))
|
||||
} else {
|
||||
resolve(port)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
50
node_modules/portscanner/package.json
generated
vendored
Normal file
50
node_modules/portscanner/package.json
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "portscanner",
|
||||
"description": "Asynchronous port scanner for Node.js",
|
||||
"scripts": {
|
||||
"coverage": "nyc npm run test",
|
||||
"test": "ava",
|
||||
"lint": "standard"
|
||||
},
|
||||
"keywords": [
|
||||
"portscanner",
|
||||
"port",
|
||||
"scanner",
|
||||
"checker",
|
||||
"status"
|
||||
],
|
||||
"version": "2.2.0",
|
||||
"preferGlobal": false,
|
||||
"homepage": "https://github.com/baalexander/node-portscanner",
|
||||
"author": [
|
||||
"Brandon Alexander <baalexander@gmail.com> (https://github.com/baalexander)",
|
||||
"Sean Massa <endangeredmassa@gmail.com> (http://massalabs.com)"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/baalexander/node-portscanner.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/baalexander/node-portscanner/issues"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "./lib"
|
||||
},
|
||||
"main": "./lib/portscanner.js",
|
||||
"dependencies": {
|
||||
"async": "^2.6.0",
|
||||
"is-number-like": "^1.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^0.4.2",
|
||||
"nyc": "^11.3.0",
|
||||
"eslint": "^3.10.2",
|
||||
"eslint-config-standard": "^6.2.1",
|
||||
"standard": "^8.5.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.4",
|
||||
"npm": ">=1.0.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
Reference in New Issue
Block a user