dnc

CLI tool to check domain names configuration and statistics
Log | Files | Refs | README | LICENSE

dnc.js (4022B)


      1 /*****************************************************************************/
      2 /*                                                                           */
      3 /* dnc 0.1.2                                                                 */
      4 /* Copyright (c) 2014-2017, Frederic Cambus                                  */
      5 /* https://github.com/fcambus/dnc                                            */
      6 /*                                                                           */
      7 /* Created: 2014-02-11                                                       */
      8 /* Last Updated: 2017-02-03                                                  */
      9 /*                                                                           */
     10 /* dnc is released under the BSD 2-Clause license.                           */
     11 /* See LICENSE file for details.                                             */
     12 /*                                                                           */
     13 /*****************************************************************************/
     14 
     15 var dns = require('dns');
     16 
     17 
     18 
     19 /**[ NPM Modules ]************************************************************/
     20 
     21 var async = require('async');
     22 var alexa = require('alexarank');
     23 
     24 var Intl = require('intl');
     25 var Table = require('cli-table');
     26 
     27 
     28 
     29 /**[ dnc ]********************************************************************/
     30 
     31 module.exports = function(config) {
     32 
     33     var table = new Table({
     34         head: ['Domain', 'NS', 'IPv4', 'IPv6', 'Alexa']
     35     });
     36 
     37     async.forEach(config.domains, function(domain, callback) {
     38 
     39         var site = {
     40             ns: '',
     41             ipv4: '',
     42             ipv6: '',
     43             alexa: ''
     44         };
     45 
     46         async.series([
     47 
     48             /**[ Get Alexa Traffic Rank ]*************************************/
     49 
     50             function(callback) {
     51                 alexa(domain, function(error, result) {
     52                     if (!error && result.rank) {
     53                         site.alexa = new Intl.NumberFormat().format(result.rank);
     54                     }
     55 
     56                     callback();
     57                 });
     58             },
     59 
     60             /**[ Get Name Servers ]*******************************************/
     61 
     62             function(callback) {
     63                 dns.resolveNs(domain, function(error, addresses) {
     64                     if (!error) {
     65                         for (var item in addresses) {
     66                             site.ns += addresses[item] + "\n";
     67                         }
     68                     }
     69 
     70                     callback();
     71                 });
     72             },
     73 
     74             /**[ Get A records ]**********************************************/
     75 
     76             function(callback) {
     77                 dns.resolve4(domain, function(error, addresses) {
     78                     if (!error) {
     79                         for (var item in addresses) {
     80                             site.ipv4 += addresses[item] + "\n";
     81                         }
     82                     }
     83 
     84                     callback();
     85                 });
     86             },
     87 
     88             /**[ Get AAAA records ]*******************************************/
     89 
     90             function(callback) {
     91                 dns.resolve6(domain, function(error, addresses) {
     92                     if (!error) {
     93                         for (var item in addresses) {
     94                             site.ipv6 += addresses[item] + "\n";
     95                         }
     96                     }
     97 
     98                     callback();
     99                 });
    100             }
    101         ], function(error) {
    102 
    103             /**[ Populate table ]*********************************************/
    104 
    105             table.push(
    106                 [domain, site.ns.trim(), site.ipv4.trim(), site.ipv6.trim(), site.alexa]
    107             );
    108 
    109             callback();
    110         });
    111 
    112     }, function(error) {
    113 
    114         /**[ Sort and display table ]*****************************************/
    115 
    116         table.sort(function(a, b) {
    117             if (a[0] < b[0]) return -1;
    118             if (a[0] > b[0]) return 1;
    119             return 0;
    120         });
    121 
    122         console.log(table.toString());
    123     });
    124 };