harryhorton / node-nmap

NPM package for interfacing with local NMAP installation
MIT License
67 stars 26 forks source link

node-nmap with async hangs #15

Closed swagnetow closed 8 years ago

swagnetow commented 8 years ago

Hey, I'm having problems with running node-nmap with async. Basically I'm trying to get 4 scans to run at a time asynchronously. The code runs fine, however, when all the scans are done, the rest of the program hangs and I have to ^C to get the program to stop. Any ideas?

Here's my code:

function NmapScan(callback) {
  var ranges = file.GetRanges();

  console.log('>> Starting nmap scan');

  async.eachLimit(ranges, 4, function(range, callback) {
    var nmapscan = new nmap.nodenmap.NmapScan(range, '-sT', '-PN', '-n', 'p80,443');

    console.log('>>> Starting scan of range: ' + range);

    nmapscan.on('complete', function(data) {
      console.log(data);
      console.log('>>> Finished scan of range: ' + range + ' (' + nmapscan.scanTime + ' ms)');
      return callback();
    });

    nmapscan.on('error', function(error) {
      console.log(error);
      return callback();
    });

    nmapscan.startScan();
  }, function (err) {
    if(err) {
      console.log(err);
    }

    return callback();
  });
}

exports.NmapScan = function(callback) {
  NmapScan(function() {
    console.log('>> Finished all nmap scans');
    return callback();
  });
}