Skip to content

Instantly share code, notes, and snippets.

@vizv
Last active January 17, 2021 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vizv/114480ccefc6d609aae1137502cdefa8 to your computer and use it in GitHub Desktop.
Save vizv/114480ccefc6d609aae1137502cdefa8 to your computer and use it in GitHub Desktop.
Trancker log analyzer
// 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