- Joined
- Jun 8, 2005
Right now I am trying to create a web spider. After all, if google, yahoo, aol and even microsoft is doing it, then why not me?
But I seemed to hit a stone. For some reason "GET / HTTP/1.0" works perfectly with woot.com and thedailywtf.com, but not with evga.com and google.com
Maybe there is something wrong with my code? I am entering the above command for the second one, but it still doesn't work with google :/
http://pastebin.com/m6dd6f2ca
But I seemed to hit a stone. For some reason "GET / HTTP/1.0" works perfectly with woot.com and thedailywtf.com, but not with evga.com and google.com
Maybe there is something wrong with my code? I am entering the above command for the second one, but it still doesn't work with google :/
http://pastebin.com/m6dd6f2ca
Code:
#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <windows.h>
#include <winsock2.h>
SOCKET sock;
using namespace std;
int main(int argc, char *argv[])
{
if(argc>9999) cout <<argv[0];
WSADATA wsaData;
sockaddr_in addr;
if(WSAStartup(0x101,&wsaData)!=0){printf("WSA FAIL");system("pause");return 0;}
sock = socket(AF_INET, SOCK_STREAM, 0);
if(sock==(unsigned int)SOCKET_ERROR){printf("SOCK ERROR");system("pause");return 0;}
char *temp = (char*) malloc(32000*sizeof(char));
if(temp==NULL){cout<<"FAILED TO ALLOCATE 32MB of RAM."; system("pause");return 0;}
printf("Please enter the website. (max 256 chars)\n");
printf("Do not enter spaces or http.\n");
printf("Ex: www.google.com \n");
fgets(temp,256,stdin); // BIG PROBLEM: FGETS STORES THE NEWLINE CHAR
for(int i=0;i<255;i++)
if(temp[i]=='\n') // SO WE LOOK FOR THE /n AND TURN IT INTO THE END
{temp[i]='\0';break;}
LPHOSTENT host;
host = gethostbyname(temp);
if(host==NULL)
{printf("DNS failure: error %i on %s",WSAGetLastError(),temp);system("pause");return 0;}
addr.sin_family = AF_INET;
addr.sin_port = htons(80);
addr.sin_addr = *((LPIN_ADDR)*host->h_addr_list);
if(connect(sock,(LPSOCKADDR)&addr,sizeof(struct sockaddr))==SOCKET_ERROR)
{printf("CRIT ERROR %i : Unable to connect to %s",WSAGetLastError(),temp);system("pause");return 0;}
printf("Type in the command\n");
fgets(temp,256,stdin);
send(sock,temp,strlen(temp),0);
recv(sock,temp,32000*sizeof(char),0);
cout << temp;
free(temp);
closesocket(sock);
system("PAUSE");
return EXIT_SUCCESS;
}