<commit_before>/*
 * ==============================================================
 * 		IPv4-Tools
 * ==============================================================
 * 		IPv4 Toolkit for NodeJS
 * ==============================================================
 * License: MIT (check attached file)
 * Author: undertuga[at]gmail[dot]com
 * RepURL: https://github.com/undertuga/ipv4-tools
 * ==============================================================
 */




IPv4Tools = function(){
	
	// importing required external dependencies
	this.async = require('async');
	this.dns = require('dns');
	this.satelize = require('satelize');
};






/*
 * Name: generateIPv4
 * Detail: Generates random IPv4 address according to desired class!
 * Receives: IPv4 class(string) | class A to E; R to random
 * Returns: false(bool) on failure / error | IPv4 address (string)
 */
IPv4Tools.prototype.generateIPv4 = function(ipclass, callback){
	
	// validating gathered ip class
	if((typeof(ipclass) === 'undefined') || (ipclass === null) || (ipclass === '') || (ipclass.length <= 0) || (ipclass.length > 1)){callback(null, false);}
	else{
		// declaring octet's (-1st) holder
		var octets = '.' + (Math.floor(Math.random() * 255) + 0) + '.' + (Math.floor(Math.random() * 255) + 0) + '.' + (Math.floor(Math.random() * 255) + 0);
		
		// matching ipv4 class
		switch(ipclass.toUpperCase()){
		
			// class A IPv4
			case 'A':
				var oc1 = Math.floor(Math.random() * 127) + 0;
				callback(null, oc1 + octets);
				break;
				
			// class B IPv4
			case 'B':
				var oc1 = Math.floor(Math.random() * 191) + 128;
				callback(null, oc1 + octets);
				break;
				
			// class C IPv4
			case 'C':
				var oc1 = Math.floor(Math.random() * 223) + 192;
				callback(null, oc1 + octets);
				break;
				
			// class D IPv4
			case 'D':
				var oc1 = Math.floor(Math.random() * 239) + 224;
				callback(null, oc1 + octets);
				break;
				
			// class E IPv4
			case 'E':
				var oc1 = Math.floor(Math.random() * 247) + 240;
				callback(null, oc1 + octets);
				break;
				
			// Random IPv4 class selection (fail safe bail out)
			case 'R':
			default:
				var oc1 = Math.floor(Math.random() * 247) + 0;
				callback(null, oc1 + octets);
				break;
		}
	}
};









/* IPv4 Validation Prototype */
IPv4Tools.prototype.validateIPv4 = function(ipv4, callback){
	
	// validating gathered data
	if((typeof(ipv4) === 'undefined') || (ipv4 === null) || (ipv4 === '') || (ipv4.length <= 0) || (ipv4.length > 16)){callback(null, false);}
	else{
		
		// check for valid ipv4 address
		ipv4.split('.').forEach(function(octect){
			if((typeof(octect) === 'undefined') || (octect === null) || (octect === '') || ((octect < 0) || (octect > 255))){callback(null, false);}
		});
		
		// return validation state
		callback(null, true);
	}
};









IPv4Tools.prototype.getNetworkClass = function(ipv4, callback){
	
	// validating gathered data
	if((typeof(ipv4) === 'undefined') || (ipv4 === null) || (ipv4 === '') || (ipv4.length <= 0) || (ipv4.length > 16)){callback(null, false);}
	else{
		
		// explode gathered ipv4 address
		ipv4 = ipv4.split('.');
		
		/*ipv4 class match*/
		if((parseInt(ipv4[0].trim()) > 0) && (parseInt(ipv4[0].trim()) <= 127)){ipv4 = null; callback(null, 'A');} // class A ipv4
		if((parseInt(ipv4[0].trim()) > 127) && (parseInt(ipv4[0].trim()) <= 191)){ipv4 = null; callback(null, 'B');} // class B ipv4
		if((parseInt(ipv4[0].trim()) > 191) && (parseInt(ipv4[0].trim()) <=  223)){ipv4 = null; callback(null, 'C');} // class C ipv4
		if((parseInt(ipv4[0].trim()) > 223) && (parseInt(ipv4[0].trim()) <= 239)){ipv4 = null; callback(null, 'D');} // class D ipv4
		if((parseInt(ipv4[0].trim()) > 239) && (parseInt(ipv4[0].trim()) <= 247)){ipv4 = null; callback(null, 'E');} // class E ipv4
		if(ipv4 !== null){callback(null, false);} // fail safe bail out
	}
};





/* Get IPv4 Network Data */
IPv4Tools.prototype.getNetworkData = function(ipv4, callback){
	
	// validating gathered data
	if((typeof(ipv4) === 'undefined') || (ipv4 === null) || (ipv4.length <= 0) || (ipv4.length > 16)){callback(null, false);}
	else{
		
		// declaring needed holders
		var buffer = {ip: ipv4}, dns = this.dns, ip = ipv4.split(".");<commit_msg>fixed zombie brainless morning dev bug! setting null and validating for not null... GO GET SOME COFFEE HOMMIE!<commit_after>/*
 * ==============================================================
 * 		IPv4-Tools
 * ==============================================================
 * 		IPv4 Toolkit for NodeJS
 * ==============================================================
 * License: MIT (check attached file)
 * Author: undertuga[at]gmail[dot]com
 * RepURL: https://github.com/undertuga/ipv4-tools
 * ==============================================================
 */




IPv4Tools = function(){
	
	// importing required external dependencies
	this.async = require('async');
	this.dns = require('dns');
	this.satelize = require('satelize');
};






/*
 * Name: generateIPv4
 * Detail: Generates random IPv4 address according to desired class!
 * Receives: IPv4 class(string) | class A to E; R to random
 * Returns: false(bool) on failure / error | IPv4 address (string)
 */
IPv4Tools.prototype.generateIPv4 = function(ipclass, callback){
	
	// validating gathered ip class
	if((typeof(ipclass) === 'undefined') || (ipclass === null) || (ipclass === '') || (ipclass.length <= 0) || (ipclass.length > 1)){callback(null, false);}
	else{
		// declaring octet's (-1st) holder
		var octets = '.' + (Math.floor(Math.random() * 255) + 0) + '.' + (Math.floor(Math.random() * 255) + 0) + '.' + (Math.floor(Math.random() * 255) + 0);
		
		// matching ipv4 class
		switch(ipclass.toUpperCase()){
		
			// class A IPv4
			case 'A':
				var oc1 = Math.floor(Math.random() * 127) + 0;
				callback(null, oc1 + octets);
				break;
				
			// class B IPv4
			case 'B':
				var oc1 = Math.floor(Math.random() * 191) + 128;
				callback(null, oc1 + octets);
				break;
				
			// class C IPv4
			case 'C':
				var oc1 = Math.floor(Math.random() * 223) + 192;
				callback(null, oc1 + octets);
				break;
				
			// class D IPv4
			case 'D':
				var oc1 = Math.floor(Math.random() * 239) + 224;
				callback(null, oc1 + octets);
				break;
				
			// class E IPv4
			case 'E':
				var oc1 = Math.floor(Math.random() * 247) + 240;
				callback(null, oc1 + octets);
				break;
				
			// Random IPv4 class selection (fail safe bail out)
			case 'R':
			default:
				var oc1 = Math.floor(Math.random() * 247) + 0;
				callback(null, oc1 + octets);
				break;
		}
	}
};









/* IPv4 Validation Prototype */
IPv4Tools.prototype.validateIPv4 = function(ipv4, callback){
	
	// validating gathered data
	if((typeof(ipv4) === 'undefined') || (ipv4 === null) || (ipv4 === '') || (ipv4.length <= 0) || (ipv4.length > 16)){callback(null, false);}
	else{
		
		// check for valid ipv4 address
		ipv4.split('.').forEach(function(octect){
			if((typeof(octect) === 'undefined') || (octect === null) || (octect === '') || ((octect < 0) || (octect > 255))){callback(null, false);}
		});
		
		// return validation state
		callback(null, true);
	}
};









IPv4Tools.prototype.getNetworkClass = function(ipv4, callback){
	
	// validating gathered data
	if((typeof(ipv4) === 'undefined') || (ipv4 === null) || (ipv4 === '') || (ipv4.length <= 0) || (ipv4.length > 16)){callback(null, false);}
	else{
		
		// explode gathered ipv4 address
		ipv4 = ipv4.split('.');
		
		/*ipv4 class match*/
		if((ipv4 !== null) && (parseInt(ipv4[0].trim()) > 0) && (parseInt(ipv4[0].trim()) <= 127)){ipv4 = null; callback(null, 'A');} // class A ipv4
		if((ipv4 !== null) && (parseInt(ipv4[0].trim()) > 127) && (parseInt(ipv4[0].trim()) <= 191)){ipv4 = null; callback(null, 'B');} // class B ipv4
		if((ipv4 !== null) && (parseInt(ipv4[0].trim()) > 191) && (parseInt(ipv4[0].trim()) <=  223)){ipv4 = null; callback(null, 'C');} // class C ipv4
		if((ipv4 !== null) && (parseInt(ipv4[0].trim()) > 223) && (parseInt(ipv4[0].trim()) <= 239)){ipv4 = null; callback(null, 'D');} // class D ipv4
		if((ipv4 !== null) && (parseInt(ipv4[0].trim()) > 239) && (parseInt(ipv4[0].trim()) <= 247)){ipv4 = null; callback(null, 'E');} // class E ipv4
		if(ipv4 !== null){callback(null, false);} // fail safe bail out
	}
};





/* Get IPv4 Network Data */
IPv4Tools.prototype.getNetworkData = function(ipv4, callback){
	
	// validating gathered data
	if((typeof(ipv4) === 'undefined') || (ipv4 === null) || (ipv4.length <= 0) || (ipv4.length > 16)){callback(null, false);}
	else{
		
		// declaring needed holders
		var buffer = {ip: ipv4}, dns = this.dns, ip = ipv4.split(".");
{'fraction_non_alphanumeric': 0.2484356894553882, 'fraction_numerical': 0.042062572421784475, 'mean_word_length': 3.573926868044515, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2447605', 'n_tokens_mistral': 3431, 'n_tokens_neox': 2967, 'n_words': 702}