基于nodejs开发的一个端口扫描

0x01 test


手贱测试下nodejs写agent看看好不好用。。。最后结果是不好用。。。

0x02 coding


var nmap = require('libnmap');
var async = require('async');



// 扫描任务执行
function nmap_service(target,callback){
  var opts = {
      timeout: 90, // 900s = 10m and increases the reliability of scan results
      range: [target]
  };
  nmap.scan(opts, function(err, report) {
    var results = {};
    // 没扫出东西
    if (report[target]['host'] != undefined){
      // 获得端口扫描列表
      var portlist = report[target]['host'][0]['ports'][0]['port'];

      results['target'] = target;
      results['ports'] = [];

      // 遍历端口
      for (var item in portlist){
        if (portlist[item]['service'] == undefined){
          continue;
        }
        if (portlist[item]['state'] == undefined){
          continue;
        }
        // 判断端口是否开放
        if (portlist[item]['state'][0]['item']['state'] == 'open'){
          results['ports'].push({'port':portlist[item]['item']['portid'],'service':portlist[item]['service'][0]['item']['name']});
        }
      }
      // 写入结果
      // 
      console.log(results)
    }
  });
}


async.map(['127.0.0.1'], nmap_service, null);

你可能感兴趣的:(基于nodejs开发的一个端口扫描)