Added verbose option

This commit is contained in:
Luca
2021-03-03 08:12:16 +01:00
parent 1a37595de0
commit 49843509e5
+15 -4
View File
@@ -32,7 +32,7 @@
void help() { void help() {
printf("dga_evaluate <file name>\n"); printf("dga_evaluate <file name> [<verbose>]\n");
exit(0); exit(0);
} }
@@ -42,6 +42,7 @@ void help() {
int main(int argc, char **argv) { int main(int argc, char **argv) {
FILE *fd; FILE *fd;
char buffer[512]; char buffer[512];
int verbose = 0;
if(argc != 2) help(); if(argc != 2) help();
fd = fopen(argv[1], "r"); fd = fopen(argv[1], "r");
@@ -51,6 +52,8 @@ int main(int argc, char **argv) {
exit(0); exit(0);
} }
if(argv[1] != NULL) verbose = 1;
if (ndpi_get_api_version() != NDPI_API_VERSION) { if (ndpi_get_api_version() != NDPI_API_VERSION) {
printf("nDPI Library version mismatch: please make sure this code and the nDPI library are in sync\n"); printf("nDPI Library version mismatch: please make sure this code and the nDPI library are in sync\n");
return -1; return -1;
@@ -68,9 +71,17 @@ int main(int argc, char **argv) {
while(fgets(buffer, sizeof(buffer), fd) != NULL) { while(fgets(buffer, sizeof(buffer), fd) != NULL) {
char *hostname; char *hostname = strtok(buffer, "\n");
hostname = strtok(buffer, "\n");
if (ndpi_check_dga_name(ndpi_str, NULL, hostname, 1)) num_detections++; if(ndpi_check_dga_name(ndpi_str, NULL, hostname, 1)) {
if(verbose)
printf("%10s\t%s\n", "[DGA]", hostname);
num_detections++;
} else {
if(verbose)
printf("%10s\t%s\n", "[NON DGA]", hostname);
}
} }
fclose(fd); fclose(fd);