Last active
August 29, 2015 13:56
-
-
Save kanazux/9042224 to your computer and use it in GitHub Desktop.
consumer em c
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 <time.h> | |
#include <stdlib.h> | |
#include <curl/curl.h> | |
#include <string.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#define MAX_STRING_LEN 6000002 | |
#define NUMT 4 | |
char *getCut(char *word) | |
{ | |
char *base = strrchr(word, '/'); | |
return base+1; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
if(argc < 2) | |
{ | |
printf("Use like: ./consumer 'url'\n"); | |
exit(0); | |
} | |
CURL *curl; | |
CURLcode resUpload, resDownload; | |
char test[MAX_STRING_LEN]; | |
double speed_upload, speed_download; | |
char *ch = "0123456789ABCDEFGHIJKLMNOPQRSTUVXWYZ"; | |
int size = strlen(ch) - 1; | |
for (int x = 0; x < 5150000;){ | |
for (int i = 0; i <= size; ++i){ | |
strcpy(&test[x],&ch[i]); | |
++x; | |
} | |
} | |
char word[] = "content="; | |
strcat(word,test); | |
FILE *fd = fopen("fileUp","a"); | |
fputs(word,fd); | |
fclose(fd); | |
FILE *nfd = fopen("fileUp","r"); | |
curl = curl_easy_init(); | |
if(curl) | |
{ | |
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20); | |
curl_easy_setopt(curl, CURLOPT_URL, argv[1]); | |
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); | |
curl_easy_setopt(curl, CURLOPT_READDATA, nfd); | |
curl_easy_setopt(curl, CURLOPT_NOBODY, 1); | |
resUpload = curl_easy_perform(curl); | |
curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload); | |
float upload = speed_upload / 1024 ; | |
fprintf(stderr, "Upload Speed: %.2f Kb/s\n", upload); | |
curl_easy_cleanup(curl); | |
} | |
char *url = argv[1]; | |
char *path = getCut(url); | |
int nletters = strlen(argv[1]) - strlen(path); | |
char nBase[nletters+1]; | |
strncpy(nBase,url+0,nletters); | |
char urlRandom[1024]; | |
strcat(urlRandom,nBase); | |
strcat(urlRandom,"random4000x4000.jpg"); | |
FILE *image = fopen("imgDown","wb"); | |
curl = curl_easy_init(); | |
if(curl){ | |
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20); | |
curl_easy_setopt(curl, CURLOPT_URL, urlRandom); | |
curl_easy_setopt(curl, CURLOPT_WRITEDATA, image); | |
resDownload = curl_easy_perform(curl); | |
curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &speed_download); | |
float download = speed_download / 1024; | |
float nominalSpeed = download / 1024 * 10; | |
fprintf(stderr, "Download Speed: %.2f Kb/s\n", download); | |
fprintf(stderr, "Nominal Speed: %.2f MB/s\n", nominalSpeed); | |
curl_easy_cleanup(curl); | |
} | |
int uStatus = remove("fileUp"); | |
if (uStatus != 0) | |
{ | |
printf("File 'fileUp' can't be removed\n"); | |
} | |
int dStatus = remove("imgDown"); | |
if (dStatus != 0) | |
{ | |
printf("File 'imgDown' can't be removed\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment