Created
July 17, 2020 04:52
-
-
Save rzjnzk/234f5fc7b614abdee85d6bbf19f9edc9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <string.h> | |
#include <linux/limits.h> | |
int main(int argc, char *argv[]) | |
{ | |
printf("begin"); | |
// Error on no args. | |
if(argc <= 1) | |
{ | |
printf("Error, no arguments provided."); | |
return 1; | |
} | |
// Seed rand. | |
srand(time(NULL)); | |
int outputArg = *argv[2]; | |
int letterArg = *argv[2]; | |
const char alphabet[] = "abcdefghijklmnopqrstuvwxyz"; | |
int charFrequency[26] = { 0 }; | |
int sum = 0; | |
char outputLineBuffer[256]; | |
const char failStr[] = "failed: Name or service not known."; | |
char inputFile[PATH_MAX]; | |
strcat(strcpy(inputFile, getenv("HOME")), "/.config/unreg-web-domain-gen/input"); | |
// Set char frequencies. | |
for(int i = 0; i < 26; i++) | |
{ | |
FILE *fp; | |
char ch; | |
fp = fopen(inputFile, "r"); | |
if (fp == NULL) | |
{ | |
printf("File is not available.\n"); | |
exit(1); | |
} | |
while((ch = fgetc(fp)) != EOF) | |
{ | |
if(ch == alphabet[i]) | |
{ | |
charFrequency[i]++; | |
} | |
} | |
fclose(fp); | |
} | |
// Sum frequencies. | |
for(int i = 0; i < 26; i++) | |
{ | |
sum += charFrequency[i]; | |
} | |
// For each output. | |
// Per address. | |
while(outputArg > 0) | |
{ | |
outputArg--; | |
FILE *fp; | |
char command[PATH_MAX] = "/bin/wget "; | |
// char *address[PATH_MAX] = { '\0' }; | |
char* address; | |
address = malloc(letterArg + 5); | |
// For each letter. | |
// Generate random letters. | |
for(int i = 0; i < letterArg; i++) | |
{ | |
// Get a random value. | |
int random = rand() % sum + 1; | |
int index = 0; | |
int sumProgression = 0; | |
// Deduce an index of `charFrequency` for a letter random of the alphabet. | |
while(random > sumProgression) | |
{ | |
sumProgression += charFrequency[index]; | |
index++; | |
} | |
// const char* name = "hello"; | |
// const char* extension = ".txt"; | |
// char* name_with_extension; | |
// name_with_extension = malloc(strlen(name)+1+4); /* make space for the new string (should check the return value ...) */ | |
// strcpy(name_with_extension, name); /* copy name into the new var */ | |
// strcat(name_with_extension, extension); /* add the extension */ | |
// Concatente to `command` C string. | |
strcat(address, alphabet[index]); | |
} | |
// // Concatenate `.com` to comlete the command. | |
// strcat(address, ".com"); | |
// strcat(command, address); | |
// // Enable reaading the output of the command. | |
// fp = popen(command,"r"); | |
// if(fp == NULL) | |
// { | |
// printf("Failed to run command\n" ); | |
// exit(1); | |
// } | |
// while(fgets(outputLineBuffer, sizeof(outputLineBuffer), fp)) | |
// { | |
// if(strstr(outputLineBuffer, failStr) != NULL) | |
// { | |
// printf(address); | |
// } | |
// } | |
// fclose(fp); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment