UNPKG

1.98 kBMarkdownView Raw
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
6The portscanner module is
7an asynchronous JavaScript port scanner for Node.js.
8
9Portscanner can check a port,
10or range of ports,
11for 'open' or 'closed' statuses.
12
13[Looking for maintainer](https://github.com/baalexander/node-portscanner/issues/25)!
14
15## Install
16
17```bash
18npm install portscanner
19```
20
21## Usage
22
23A brief example:
24
25```javascript
26var portscanner = require('portscanner')
27
28// Checks the status of a single port
29portscanner.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.
36portscanner.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.
42portscanner.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
47portscanner.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'
52portscanner.findAPortNotInUse(3000, 4000, function(error, port) {
53 console.log('PORT IN USE AT: ' + port)
54})
55
56// And use promises
57portscanner.findAPortNotInUse(3000, 4000).then(function(port) {
58 console.log('PORT IN USE AT: ' + port)
59})
60```
61
62The example directory contains a more detailed example.
63
64## Test
65
66```sh
67npm test
68```
69
70## Future
71
72Please create issues or pull requests
73for port scanning related features
74you'd like to see included.
75
76## License (MIT)
77
78[MIT](LICENSE)
79