Advertisement
imk0tter

cURL twitline

Jul 18th, 2011
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include <math.h>
  6. #include <curl/curl.h>
  7.  
  8. #define WIN32_LEAN_AND_MEAN
  9. #include <windows.h>
  10. #include <process.h>
  11.  
  12. #define URL_BASE "http://twitter.com/statuses/update.xml"
  13.  
  14. #define TWITLINE_VERSION "1.0"
  15.  
  16. int fileLineCount(FILE*);
  17. void fillStrings(FILE*,char**,int);
  18. void cleanStrings(char**,int);
  19. void curl_thread(void * _options);
  20. typedef struct {
  21.     char * postField;
  22.     char * userPwd;
  23.     char * proxy;
  24.     long proxyType;
  25.     long padding;
  26. } CURLOPTIONS;
  27.  
  28. int success = 0;
  29. int threadEnd = 0;
  30.  
  31. int main(int argc, char *argv[])
  32. {
  33.   char *appname = argv[0];
  34.  
  35.     FILE * accounts = 0;
  36.     FILE * comments = 0;
  37.  
  38.     FILE * s4proxys = 0;
  39.     FILE * s5proxys = 0;
  40.  
  41.     bool _s4proxys = false;
  42.     bool _s5proxys = false;
  43.  
  44.     int accountsCount = 0;
  45.     int commentsCount = 0;
  46.  
  47.     int s4proxysCount = 0;
  48.     int s5proxysCount = 0;
  49.  
  50.     int s4proxysCurrent = 0;
  51.     int s5proxysCurrent = 0;
  52.  
  53.     char ** accountsStrings = 0;
  54.     char ** commentsStrings = 0;
  55.  
  56.     char ** s4proxysStrings = 0;
  57.     char ** s5proxysStrings = 0;
  58.   if (argc > 1) {
  59.     /* parse input parameters */
  60.     for (argc--, argv++; *argv; argc--, argv++) {
  61.       if (strncmp(*argv, "-", 1) == 0) {
  62.         if (strncmp(*argv, "-H", 2) == 0) {
  63.           fprintf(stderr,
  64.                   "\rUsage: %s [-a=accounts.txt] [-c=comments.txt] [-s4=socks4.txt] [-s5=socks5.txt]\n",
  65.                   appname);
  66.           exit(1);
  67.         } else if (strncmp(*argv, "-V", 2) == 0) {
  68.           fprintf(stderr, "\r%s %s - %s\n",
  69.                   appname, TWITLINE_VERSION, curl_version());
  70.           exit(1);
  71.         } else if (strncmp(*argv, "-a=", 3) == 0) {
  72.             int len = strlen(*argv) - 3;
  73.             char * fileName = (char*)malloc(len+1);
  74.             strncpy(fileName,*argv+3,len);
  75.             fileName[len] = '\0';
  76.             accounts = fopen(fileName,"r");
  77.             free(fileName);
  78.             if (accounts == NULL) {
  79.                 fprintf(stderr,"\r%s: invalid accounts file\n",appname);
  80.                 exit(1);
  81.             }
  82.         } else if (strncmp(*argv, "-c=", 3) == 0) {
  83.             int len = strlen(*argv) - 3;
  84.             char * fileName = (char*)malloc(len+1);
  85.             strncpy(fileName,*argv+3,len);
  86.             fileName[len] = '\0';
  87.             comments = fopen(fileName,"r");
  88.             free(fileName);
  89.             if (comments == NULL) {
  90.                 fprintf(stderr,"\r%s: invalid comments file\n",appname);
  91.                 exit(1);
  92.             }
  93.         } else if (strncmp(*argv, "-s4=", 4) == 0) {
  94.             int len = strlen(*argv) - 4;
  95.             char * fileName = (char*)malloc(len+1);
  96.             strncpy(fileName,*argv+4,len);
  97.             fileName[len] = '\0';
  98.             s4proxys = fopen(fileName,"r");
  99.             free(fileName);
  100.             if (s4proxys == NULL) {
  101.                 fprintf(stderr,"\r%s: invalid socks4 file\n",appname);
  102.                 exit(1);
  103.             }
  104.         } else if (strncmp(*argv, "-s5=", 4) == 0) {
  105.             int len = strlen(*argv) - 4;
  106.             char * fileName = (char*)malloc(len+1);
  107.             strncpy(fileName,*argv+4,len);
  108.             fileName[len] = '\0';
  109.             s5proxys = fopen(fileName,"r");
  110.             free(fileName);
  111.             if (s5proxys == NULL) {
  112.                 fprintf(stderr,"\r%s: invalid socks5 file\n",appname);
  113.                 exit(1);
  114.             }
  115.         } else {
  116.           fprintf(stderr, "\r%s: invalid or unknown option %s\n",appname, *argv);
  117.           exit(1);
  118.         }
  119.       }
  120.     }
  121.   }
  122.   if (accounts == NULL) {
  123.     fprintf(stderr,"\r%s: invalid accounts file\n",appname);
  124.     exit(1);
  125.   }
  126.   if (comments == NULL) {
  127.     fprintf(stderr,"\r%s: invalid comments file\n",appname);
  128.     exit(1);
  129.   }
  130.  // if (s4proxys == NULL && s5proxys == NULL) {
  131.  //  fprintf(stderr,"\r%s: no proxy list specified\n",appname);
  132.  //  exit(1);
  133.  //}
  134.  
  135.   accountsCount = fileLineCount(accounts);
  136.   commentsCount = fileLineCount(comments);
  137.  
  138.   if (s4proxys != NULL) s4proxysCount = fileLineCount(s4proxys);
  139.   if (s5proxys != NULL) s5proxysCount = fileLineCount(s5proxys);
  140.  
  141.   accountsStrings = (char**)malloc(sizeof(char*) * accountsCount);
  142.   fillStrings(accounts,accountsStrings,accountsCount);
  143.  
  144.   commentsStrings = (char**)malloc(sizeof(char*) * commentsCount);
  145.   fillStrings(comments,commentsStrings,commentsCount);
  146.  
  147.   if (s4proxys != NULL) {
  148.     s4proxysStrings = (char**)malloc(sizeof(char*) * s4proxysCount);
  149.     fillStrings(s4proxys,s4proxysStrings,s4proxysCount);
  150.   }
  151.   if (s5proxys != NULL) {
  152.     s5proxysStrings = (char**)malloc(sizeof(char*) * s5proxysCount);
  153.     fillStrings(s5proxys,s5proxysStrings,s5proxysCount);
  154.   }
  155.   /* print separator line */
  156.   printf("-----------------------------------------------------------\n");
  157.  
  158.   int totalProxys = s4proxysCount + s5proxysCount;
  159.  
  160.   //int accountsPerProxy = fabs((float)(accountsCount / totalProxys));
  161.   int accountsPerProxy = 0;
  162.   char * proxy = 0;
  163.   bool isSocks4 = true;
  164.  
  165.   curl_global_init(CURL_GLOBAL_ALL);
  166.  
  167.   for (int i = 0; i < accountsCount; ++i) {
  168.       char * randomComment = commentsStrings[rand() % commentsCount];
  169.       char * postField = (char*)malloc(strlen(randomComment) + 8);
  170.  
  171.       wsprintf(postField,"status=%s",randomComment);
  172.  
  173.  
  174.       /*if (i % accountsPerProxy == 0) {
  175.         if (s4proxysCurrent < s4proxysCount) {
  176.             isSocks4 = true;
  177.             proxy = s4proxysStrings[s4proxysCurrent++];
  178.         }
  179.         else {
  180.             if (s5proxysCurrent < s5proxysCount) {
  181.                 isSocks4 = false;
  182.                 proxy = s5proxysStrings[s5proxysCurrent++];
  183.             }
  184.         }
  185.       }*/
  186.       CURLOPTIONS * options = (CURLOPTIONS*)malloc(sizeof(CURLOPTIONS));
  187.       options->postField = postField;
  188.       options->userPwd = accountsStrings[i];
  189.       options->proxy = proxy;
  190.       options->proxyType = (isSocks4 ? CURLPROXY_SOCKS4 : CURLPROXY_SOCKS5);
  191.       _beginthread(curl_thread,0,(void*)options);
  192.   }
  193.   while(threadEnd < accountsCount) { Sleep(10); }
  194.   printf("%s: Total Accounts: %d, Total Proxys: %d\n",appname,accountsCount,totalProxys);
  195.   printf("%s: Accounts per proxy: %d, Successful Logins: %d\n",appname,accountsPerProxy,success);
  196.   printf("-----------------------------------------------------------\n");
  197.  
  198.   return 0;
  199. }
  200. void curl_thread(void * _options) {
  201.     CURLOPTIONS * options = (CURLOPTIONS*)_options;
  202.       CURL * curl_handle = curl_easy_init();
  203.       curl_easy_setopt(curl_handle, CURLOPT_URL, URL_BASE);
  204.       curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 6);
  205.       curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
  206.       curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, options->postField);
  207.       curl_easy_setopt(curl_handle, CURLOPT_USERPWD, options->userPwd);
  208.       //curl_easy_setopt(curl_handle, CURLOPT_PROXY,options->proxy);
  209.       //curl_easy_setopt(curl_handle, CURLOPT_PROXYTYPE, options->proxyType);
  210.       long res = curl_easy_perform(curl_handle);
  211.       curl_easy_cleanup(curl_handle);
  212.     free(options);
  213.     if (res == 0) ++success;
  214.     threadEnd++;
  215. }
  216. void cleanStrings(char ** strings, int count) {
  217.     for (int i = 0; i < count; ++i) {
  218.         free(strings[i]);
  219.     }
  220.     free(strings);
  221. }
  222. void fillStrings(FILE * file, char ** strings, int count) {
  223.     int x = 0;
  224.     for (; x < count;) {
  225.         int j = 0;
  226.         char c = 0;
  227.         char str[256];
  228.         do {
  229.             c = fgetc(file);
  230.             if (c != '\n') {
  231.                 str[j++] = c;
  232.             }
  233.         } while (c != '\n');
  234.         if (j > 0) {
  235.             char * _str = (char*)malloc(j+1);
  236.             strncpy(_str,str,j);
  237.             _str[j] = '\0';
  238.             strings[x++] = _str;
  239.         }
  240.     }
  241.     rewind(file);
  242. }
  243. int fileLineCount(FILE * f) {
  244.     int c = 0,n = 0,j = 0;
  245.     do {
  246.         c = fgetc(f);
  247.         if (c == '\n') {
  248.             if (j > 0) ++n;
  249.             j = 0;
  250.         }
  251.         else {
  252.             ++j;
  253.         }
  254.     } while (c != EOF);
  255.     rewind(f);
  256.     return n;
  257. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement