Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Code from someone else, fixed to store all the packets
- #include <winsock2.h>
- #include <windows.h>
- #include <iostream>
- #include <fstream>
- #pragma comment(lib,"ws2_32.lib")
- using namespace std;
- /*int receive_basic(int s)
- {
- int size_recv , total_size= 0;
- char chunk[CHUNK_SIZE];
- //loop
- while(1)
- {
- memset(chunk ,0 , CHUNK_SIZE); //clear the variable
- if((size_recv = recv(s , chunk , CHUNK_SIZE , 0) ) < 0)
- {
- break;
- }
- else
- {
- total_size += size_recv;
- printf("%s" , chunk);
- }
- }
- return total_size;
- }*/
- int main (){
- ofstream myfile;
- myfile.open("page.html");
- char message[] = "GET /index.html?gfe_rd=cr&ei=PrKrVfi4CrLF8AeLjbvoDg HTTP/1.1\r\n"
- "Host: www.google.com\r\n"
- "Accept: */*\r\n"
- "Accept-Language: en-us\r\n"
- "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\n"
- "\r\n";
- WSADATA wsaData;
- if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
- cout << "WSAStartup failed.\n";
- system("pause");
- return 1;
- }
- SOCKET Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
- struct hostent *host;
- host = gethostbyname("www.google.com");
- SOCKADDR_IN SockAddr;
- SockAddr.sin_port=htons(80);
- SockAddr.sin_family=AF_INET;
- SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
- cout << "Connecting...\n";
- if(connect(Socket,(SOCKADDR*)(&SockAddr),sizeof(SockAddr)) != 0){
- cout << "Could not connect";
- system("pause");
- return 1;
- }
- cout << "Connected.\n";
- //u_long nbio = 1;
- //ioctlsocket(Socket,FIONBIO,&nbio);
- send(Socket,message, strlen(message),0);
- char buffer[51200]; //What is this 'optimization' you speak of?
- int nDataLength;
- while ((nDataLength = recv(Socket,buffer,51200,0)) > 0){
- int i = 0;
- //while (buffer[i] >= 32 || buffer[i] == '\n' || buffer[i] == '\r')
- // {
- while(i != nDataLength) //'Ghost-Timeout' fix (Not all the packets were being copied to the buffer)
- {
- myfile << buffer[i];
- cout << buffer[i];
- i += 1;
- }
- //}
- }
- myfile.close();
- closesocket(Socket);
- WSACleanup();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment