port scan
Last active
June 9, 2018 12:20
-
-
Save eli9000/f04eb7433321cc9a75cfdd4e5fe1169e to your computer and use it in GitHub Desktop.
Port scan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
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) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"name": "dumb-derek", "version": "0.0.0", "bin": "./index.js"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment