-
-
Save hengkiardo/6789740 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
// pick a random port between 1025 and 65535 | |
// check using netstat to see if port is used | |
var exec = require('child_process').exec; | |
var port; | |
var _port; | |
var interval; | |
var handle = function(err, stdout, stderr) { | |
if (!stdout.trim().length) { | |
console.log('port ' + _port + ' available!'); | |
port = _port; | |
clearInterval(interval); | |
} | |
}; | |
interval = setInterval(function() { | |
_port = Math.floor(Math.random() * 65535) + 1025; | |
exec('netstat -na | grep ' + _port, handle); | |
}, 500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment