1 | # portscanner
|
2 |
|
3 | [![npm](https://img.shields.io/npm/v/portscanner.svg)](https://www.npmjs.com/package/portscanner)
|
4 | [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
|
5 |
|
6 | The portscanner module is
|
7 | an asynchronous JavaScript port scanner for Node.js.
|
8 |
|
9 | Portscanner can check a port,
|
10 | or range of ports,
|
11 | for 'open' or 'closed' statuses.
|
12 |
|
13 | [Looking for maintainer](https://github.com/baalexander/node-portscanner/issues/25)!
|
14 |
|
15 | ## Install
|
16 |
|
17 | ```bash
|
18 | npm install portscanner
|
19 | ```
|
20 |
|
21 | ## Usage
|
22 |
|
23 | A brief example:
|
24 |
|
25 | ```javascript
|
26 | var portscanner = require('portscanner')
|
27 |
|
28 | // Checks the status of a single port
|
29 | portscanner.checkPortStatus(3000, '127.0.0.1', function(error, status) {
|
30 | // Status is 'open' if currently in use or 'closed' if available
|
31 | console.log(status)
|
32 | })
|
33 |
|
34 | // Find the first available port. Asynchronously checks, so first port
|
35 | // determined as available is returned.
|
36 | portscanner.findAPortNotInUse(3000, 3010, '127.0.0.1', function(error, port) {
|
37 | console.log('AVAILABLE PORT AT: ' + port)
|
38 | })
|
39 |
|
40 | // Find the first port in use or blocked. Asynchronously checks, so first port
|
41 | // to respond is returned.
|
42 | portscanner.findAPortInUse(3000, 3010, '127.0.0.1', function(error, port) {
|
43 | console.log('PORT IN USE AT: ' + port)
|
44 | })
|
45 |
|
46 | // You can also pass array of ports to check
|
47 | portscanner.findAPortInUse([3000, 3005, 3006], '127.0.0.1', function(error, port) {
|
48 | console.log('PORT IN USE AT: ' + port)
|
49 | })
|
50 |
|
51 | // And skip host param. Default is '127.0.0.1'
|
52 | portscanner.findAPortNotInUse(3000, 4000, function(error, port) {
|
53 | console.log('PORT IN USE AT: ' + port)
|
54 | })
|
55 |
|
56 | // And use promises
|
57 | portscanner.findAPortNotInUse(3000, 4000).then(function(port) {
|
58 | console.log('PORT IN USE AT: ' + port)
|
59 | })
|
60 | ```
|
61 |
|
62 | The example directory contains a more detailed example.
|
63 |
|
64 | ## Test
|
65 |
|
66 | ```sh
|
67 | npm test
|
68 | ```
|
69 |
|
70 | ## Future
|
71 |
|
72 | Please create issues or pull requests
|
73 | for port scanning related features
|
74 | you'd like to see included.
|
75 |
|
76 | ## License (MIT)
|
77 |
|
78 | [MIT](LICENSE)
|
79 |
|