Icontem

File: test/discover.js

Recommend this page to a friend!
  Classes of Jason Gerfen  >  Node nmap  >  test/discover.js  >  Download  
File: test/discover.js
Role: Example script
Content type: text/plain
Description: Example script
Class: Node nmap
Scan a network for computers using nmap
Author: By
Last change: v0.4.14: Fix for .match()
Date: 11 months ago
Size: 1,158 bytes
 

Contents

Class file image Download
/*!
 * libnmap
 * Copyright(c) 2013-2018 Jason Gerfen <jason.gerfen@gmail.com>
 * License: MIT
 */

'use strict'

const nmap = require('../');
const timeout = 1024 * 1024 * 3;
const chai = require('chai');
const should = chai.should();
const expect = chai.expect;
const ifaces = require('os').networkInterfaces();

describe('nmap', function () {
  context('discovery method', function () {

    this.timeout(timeout);

    it('validate report', function (done) {

      nmap.discover(function (err, report) {

        /* If 'subnet' doesn't exist in os.networkInterfaces() expect errors */
        for (let adapter in ifaces) {
          if (!ifaces[adapter][0].internal) {
            if (!ifaces[adapter][0].hasOwnProperty('subnet')) {
              try {
                done();
              }
              catch (error) {
                done(error);
              }
            }
            else {
              try {
                should.not.exist(err);
                should.exist(report);
              }
              catch (error) {
                done(error);
              }
            }
          }
        }
      });
    });
  });
});