//Constants  
const SERIAL = 0;
const BEGIN_IP = 1;
const END_IP = 2;
const TOTAL_COUNT = 3;
const CIDR_MAX = 32;
const EXCLUDE_NETWORK_ADDRESS = 1;


//Imports
var CIDR = require('cidr-js');
var cidr = CIDR();
var csv_writer = require('fast-csv');
var csvReaderStream = require('csv-reader');
var fs = require('fs');



exports.generate_ip_list = function (ip_cidr) {
    // CSV Stream 
    var csv_stream = fs.createReadStream(read_file_path, 'utf-8');

    var ip_count_dict = [];
    var ip_list = [];



    // Returns list of valid ip
    function get_valid_ip_list(start_ip, count) {
        var _cidr = get_CIDR(+count);
        var query_ip = start_ip + "/" + _cidr;
        return cidr.list(query_ip).slice(EXCLUDE_NETWORK_ADDRESS, count - EXCLUDE_NETWORK_ADDRESS);
    }



};


exports.read_csv = function (read_file_path) {

    // exclude first row 
    var first_row = true;

    // Get CIDR based on count 
    function get_CIDR(count) {
        return (CIDR_MAX - Math.log2(count))
    }

    var ips = [];
    // CSV Stream 
    var csv_stream = fs.createReadStream(read_file_path, 'utf-8');

    csv_stream.pipe(csvReaderStream()).on('data', function (row) {
            // console.log(row);
            if (!first_row) {
                ips.push({
                    ip: row[BEGIN_IP] + "/" + get_CIDR(+row[TOTAL_COUNT]),
                    count: +row[TOTAL_COUNT]
                });
            }
            first_row = false;
        })
        .on('end', function (data) {
            console.log("FINISHED READING");
        });

    return ips;
};
@@ -358,356 +358,56 @@
 (ip_
-cidr) %7B%0A    // CSV Stream %0A    var csv_stream = fs.createReadStream(read_file_path, 'utf-8');%0A%0A    var ip_count_dict = %5B%5D;%0A    var ip_list = %5B%5D;%0A%0A%0A%0A    // Returns list of valid ip%0A    function get_valid_ip_list(start_ip, count) %7B%0A        var _cidr = get_CIDR(+count);%0A        var query_ip = start_ip + %22/%22 + _cidr;%0A        return cidr.list(query_ip
+details) %7B%0A    return cidr.list(ip_details%5B'ip'%5D
 ).sl
@@ -435,21 +435,36 @@
 DDRESS, 
++ip_details%5B'
 count
+'%5D
  - EXCLU
@@ -488,17 +488,8 @@
 S);%0A
-    %7D%0A%0A%0A%0A
 %7D;%0A%0A

fix ip.js