Last active
January 17, 2021 03:39
-
-
Save vizv/114480ccefc6d609aae1137502cdefa8 to your computer and use it in GitHub Desktop.
Trancker log analyzer
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
// gcc -Wall tracker_log_analyzer.c && ./a.out | sort | uniq -c | sort -nr > rank.txt | |
#include<stdio.h> | |
#include<stdlib.h> | |
#include<string.h> | |
#include<ctype.h> | |
#define BUF_SIZE (1024 * 64) | |
#define PREFIX "info_hash=" | |
int main(int argc, char *argv[]) { | |
char buf[BUF_SIZE], hex[64], *ps, *pe, ch; | |
FILE *f = fopen("2096.log", "r"); | |
while (fgets(buf, BUF_SIZE, f) != NULL) { | |
ps = strstr(buf, PREFIX); | |
if (!ps) continue; | |
for (pe = ps + strlen(PREFIX), ps = hex; *pe != ' ' && *pe != '&';) { | |
ch = *pe++; | |
switch (ch) { | |
case '%': | |
*ps++ = tolower(*pe++); | |
*ps++ = tolower(*pe++); | |
break; | |
case '+': | |
ch = ' '; | |
default: | |
snprintf(ps, 3, "%02x", ch); | |
ps += 2; | |
} | |
} | |
*ps = '\0'; | |
puts(hex); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment