1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
#include "stdafx.h"
#include <winsock2.h>
#pragma comment(lib,"ws2_32.lib")
#if defined(__WIN32)
#define SLEEP(x) Sleep(x)
#else
#define SLEEP(x) sleep(x/1000)
#endif
int _tmain(int argc, _TCHAR* argv[])
{
FILE* fichier = NULL;
char * content_1;
fichier = fopen("test.txt", "a");
if (fichier != NULL)
{
printf("ouvertur du fichier test.txt réussi");
}
else
{
printf("Impossible d'ouvrir le fichier test.txt");
}
WSADATA m_WSAData;
if (WSAStartup (MAKEWORD(2, 0), &m_WSAData) == 0)
{
SOCKET m_Socket;
int iResult ;
struct sockaddr_in m_ServerAddress={0};
unsigned short m_Port = 80;
unsigned short port;
port = 80;
m_ServerAddress.sin_family = AF_INET;
m_ServerAddress.sin_port = htons(m_Port); // htons ()
m_ServerAddress.sin_addr.s_addr =inet_addr ("46.33.75.176");
memset(&(m_ServerAddress.sin_zero), '\0', 8);
if ((m_Socket = socket(AF_INET, SOCK_STREAM, 0)) != INVALID_SOCKET)
{
printf ("Connecting to %s\nOn port: %d\nProtocol TCP/IP\n", "46.33.75.176", 80);
if (connect (m_Socket, (struct sockaddr *) &m_ServerAddress, sizeof (m_ServerAddress)) == SOCKET_ERROR)
{
printf("connect function failed with error: %ld\n", WSAGetLastError());
printf ("[SOCKET] - Problem while connection to server.\n");
printf("%d\n",SOCKET_ERROR);}
else
{ printf ("[SOCKET] - Connected to server.\n"); }
}
else
{ printf ("[SOCKET] - Problem while socket() : invalid socket.\n"); }
char URL[1024];
char Content[1000];
int i = 0;
for(i=0;i<1023;i++)
{
URL[i]='2';
}
URL[1023]='\0';
i = 0;
for(i=0;i<999;i++)
{
Content[i]='1';
}
Content[999]='\0';
printf("%x\n",URL);
printf("%x\n",Content);
printf("%s\n",URL);
printf("%s\n",Content);
int ReceivedBytes, SendedBytes, Size;
sprintf (URL, "GET %s HTTP/1.0\r\nHost:1.ajax.lecho.be\r\nAccept: text/javascript\r\nContent-Type: text/javascript;charset= UTF-8\r\nConnection: keep-alive\r\n\r\n", "/rtq/?reqtype=simple"es=360015511&lightquotes=&group=g30_q_p");
Size = sizeof(m_ServerAddress);
if (m_Socket != INVALID_SOCKET)
{
SendedBytes = send (m_Socket, URL, sizeof(URL)+1, 0);
if (SendedBytes >= 0)
{
printf ("[SENDING] - %d Bytes sended.\n", SendedBytes);
}
else
{
printf ("[SENDING] - Problem while sending message :\n%s", URL);
}
ReceivedBytes = recv (m_Socket, Content, sizeof(Content)-1, 0);
printf("%d\n",ReceivedBytes);
if (ReceivedBytes <= 0)
{
printf ("Error #%d\n", WSAGetLastError ());
printf ("[INFO] - Size of structur : %d, Size of content : %d\n", sizeof (sockaddr), sizeof (m_ServerAddress));
}
else
{
printf ("[%d] - %s\n", ReceivedBytes, Content);
if (fichier != NULL)
{
fputs(Content, fichier);
}
}
}
else
{
printf ("[SOCKET] - Error invalid socket\n");
}
fclose(fichier);
system("pause");
}
return 0;
} |
Partager