网站文件返回
#include <stdio.h>
#include <string.h>
#include <WinSock2.h>
#pragma comment(lib,"ws2_32.lib")
int main(intargc,char*argv[])
{
if(argc!=2){
printf("Useage : scan [IP address]\n");
return(1);
}
structsockaddr_in blah;
structhostent *he;
WSADATA wsaData;
WORD wVersionRequested;
SOCKET sock;
charbuff[4096];
char*ex[2];
ex[1]="GET /index.html HTTP/1.0\n\n";
ex[2]="GET /noindex.htm HTTP/1.0\n\n";
wVersionRequested= MAKEWORD( 2, 2 );
if(WSAStartup(wVersionRequested , &wsaData)){
printf("Winsock Initialization failed.\n");
exit(1);
}
if((sock=socket(AF_INET,SOCK_STREAM,0))==INVALID_SOCKET){
printf("Can not create socket.\n");
exit(1);
}
sock =socket(AF_INET,SOCK_STREAM,0);
blah.sin_family= AF_INET;
blah.sin_port= htons(80);
blah.sin_addr.s_addr= inet_addr(argv[1]);
if((he=gethostbyname(argv[1]))!=NULL){
memcpy((char*)&blah.sin_addr.s_addr,he->h_addr,he->h_length);
}
else{
if((blah.sin_addr.s_addr=inet_addr(argv[1]))==-1){
WSACleanup();
exit(1);
}
}
if(connect(sock,(struct sockaddr*)&blah,sizeof(blah))==0){
send(sock,ex[1],strlen(ex[1]),0);
recv(sock,buff,sizeof(buff),0);
printf("%s",buff);
send(sock,ex[2],strlen(ex[2]),0);
recv(sock,buff,sizeof(buff),0);
printf("%s",buff);
}
closesocket(sock);
WSACleanup();
return(1);
}