baalexander / node-portscanner

An asynchronous port scanner for Node.js.
MIT License
295 stars 46 forks source link

Batch scan a set of ports #3

Open baalexander opened 12 years ago

baalexander commented 12 years ago

Originally, portscanner would scan as many ports as it could and the first to return with a status was returned. Unfortunately, this can throw an error on systems when scanning more than 50 ports or so at a time (see Issue #2). The fix for Issue #2 waits for the status of a port before scanning the next one.

But c'mon, waiting is node is a waste. I propose scanning a batch of 50 ports asynchronously, then if none of those return a matching port status, try the next batch of 50.

yoshuawuyts commented 10 years ago

You could consider using [supertest](github. om/visionmedia/supertest) to test http asynchronously. Give it a try, maybe you'll like it.

laggingreflex commented 7 years ago

bluebird promise library has a concurrency feature out of the box which is perfect for this scenario. I almost implemented it and it seemed to work great, showing a massive improvement when scanning all 65k ports, but I ran into an issue - processing in batch doesn't guarantee the first port found will be the first one that was provided in the range or list. For eg. findPortNotInUse(3000, 65000) is normally expected to return 3000 with the old code, but with this concurrent batching it returns anything like 3049 as the first result (asynchronously speaking).

There could be a couple of solutions, like just accepting whatever port it finds first (like 3049 instead of 3000). Or waiting for it to go through the entire range or list and then pick the first one from the resultant list.

Thoughts?