C
candyania
Unregistered / Unconfirmed
GUEST, unregistred user!
#include <windows.h>
#pragma comment (lib, "ws2_32")
#include <stdio.h>
#include <string.h>
#define TIMEOUT 5
//#include "http.h"
FILE *pf;
CRITICAL_SECTION cs;
BOOL flag = true;
int cou = 0;
int SocketStatus(SOCKET s, char x, long timeout);
DWORD WINAPI SndFun(LPVOID pvoid);
int main(int argc, char *argv[])
{
DWORD dTime_start = GetTickCount();
//printf("/n%u/n",GetTickCount() - dTime_start);
//int co;
//scanf("%d", &co);
WORD wVersionRequest = MAKEWORD(2, 2);// [red]这里makeword带的两个参数什么意思啊?? [/red]
WSADATA wsaData;//The WSADATA structure is used to store Windows Sockets
//initialization information returned by a call to the AfxSocketInit global function.
WSAStartup(wVersionRequest, &wsaData);//现在是加载Winsock库,如果WSAStartup()函数返回值为0,说明加载成功,程序可以继续
//往下执行
if (wsaData.wVersion != wVersionRequest)//[red]为什么要看是否相等??[/red] {
printf("the version is wrong");
return 0;//加载的winsock库不成功
}
struct sockaddr_in server_addr;//[red]这里是什么意思??[/red]
memset(&server_addr, 0, sizeof(sockaddr_in));//memset用来对一段内存空间全部设置为某个字符,一般用在对定义的字符串进行初始化为‘ ’或‘/0’;
//这里将所有的sockaddr_in的内存初始化为0
[red]server_addr.sin_addr.S_un.S_addr[/red] = inet_addr("211.83.121.88");
//这个是什么??还有下面的server_addr.sin_family也不知道是什么
server_addr.sin_family = 2;
server_addr.sin_port = htons(80);
//61.152.157.72
int threadnum = 10;
DWORD threadid;
HANDLE hThd[64];
pf = fopen("data_wang.txt", "r");//这个txt文件在哪个文件夹里的?
//做什么用的?是不是记录扫描的结果?
if (pf == NULL)
{
printf("open data wrong/n");
return 0;
}
InitializeCriticalSection(&cs);//初始化一个临界区
for (int i=0;
i<64;
i++)
{
hThd = CreateThread(NULL, 0, SndFun, &server_addr, 0, &threadid);
}
/*FILE *pf;
pf = fopen("wang.txt", "r");
char test1[50];
char test2[10];
fgets(test1, 50, pf);
printf(test1);
fgets(test2, 10, pf);
// the next enter
printf(test2);
fclose(pf);*/
WaitForMultipleObjects(64, hThd, TRUE, INFINITE);
fclose(pf);
printf("/n%u/n",GetTickCount() - dTime_start);
return 1;
}
DWORD WINAPI SndFun(LPVOID pvoid)
{
while (1)
{
char buffer_rcv[65536] = {0};
char buffer_snd[206] = {0};
SOCKET client_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
int timeout = TIMEOUT*1000;
// Send time out
setsockopt(client_socket, SOL_SOCKET, SO_SNDTIMEO,(char *)&timeout,sizeof(timeout));
timeout = TIMEOUT*1000;
// Receive time out
setsockopt(client_socket, SOL_SOCKET, SO_RCVTIMEO,(char *)&timeout,sizeof(timeout));
unsigned long argp = 1; // Set 0:blocking or 1:nonblocking mode socket
ioctlsocket(client_socket, FIONBIO, &argp);
/*struct fd_set socket_fd_set;
struct timeval timeout_timeval;
timeout_timeval.tv_sec = 2;
//wait out!
timeout_timeval.tv_usec = 0;
FD_ZERO(&socket_fd_set);
FD_SET(client_socket, &socket_fd_set);*/
sockaddr *server_addr = (sockaddr *)pvoid;
connect(client_socket, server_addr, sizeof(sockaddr_in));
int status = SocketStatus(client_socket, 'w', TIMEOUT);
//status: 0: timeout;
//....... -1: wrong;
//....... >0: right;
//select(client_socket+1, NULL, &socket_fd_set, NULL, &timeout_timeval);
if (status<=0)
{
printf("sokcetstatus(w) error/n");
closesocket(client_socket);
return 0;
}
/*status = SocketStatus(client_socket, 'r', 0);
if (status<0)
{
printf("sokcetstatus(r) error/n");
closesocket(client_socket);
return 0;
}
if (status>0)
{
recv(client_socket, buffer_rcv, sizeof(buffer_rcv), 0);
printf(buffer_rcv);
}*/
/*status = SocketStatus(client_socket, 'w', TIMEOUT*2);
if (status<=0)
{
printf("sokcetstatus(w) error/n");
closesocket(client_socket);
return 0;
}*/
//strncat(buffer_snd, " HTTP/1.0/x0D/x0A/x0D/x0A", sizeof(buffer_snd));
EnterCriticalSection(&cs);
if (flag) fgets(buffer_snd, 206, pf);
else
goto tt;
if (!strcmp(buffer_snd, "$end$")) {flag = false;
goto tt;}
LeaveCriticalSection(&cs);
strncat(buffer_snd, "/x0D/x0A", sizeof(buffer_snd));
int packet_length = strlen(buffer_snd);
send(client_socket, buffer_snd, packet_length, 0); //
/*fseek(pfile, 0, SEEK_END);
fwrite(buffer_snd, 1, packet_length, pfile);
printf(buffer_snd);
printf("/n");*/
//printf(buffer_snd);
//printf("/n");
status = SocketStatus(client_socket, 'r', 2);
if (status<0)
{
printf("sokcetstatus(r) error/n");
closesocket(client_socket);
return 0;
}
int count = recv(client_socket, buffer_rcv, sizeof(buffer_rcv), 0);
/*fseek(pfile, 0, SEEK_END);
fwrite(buffer_rcv, 1, count, pfile);*/
//printf(buffer_rcv);
//printf("/n");
//if (strstr(buffer_rcv, "DAV: ")!=NULL) printf("the result: have dav hole./n");
//else
printf("the result: not have dav hole./n");
//HTTP_HEAD *http_head;
//http_head = (HTTP_HEAD *)buffer_rcv;
//printf("%d/n",atoi(http_head->status_n));
closesocket(client_socket);
}
tt: LeaveCriticalSection(&cs);
return 1;
}
int SocketStatus(SOCKET s, char x, long timeout)
{
struct timeval timeout_timeval;
timeout_timeval.tv_sec = timeout;
timeout_timeval.tv_usec = 0;
struct fd_set socket_fd_set;
FD_ZERO(&socket_fd_set);
FD_SET(s, &socket_fd_set);
int status;
switch(x)
{
case 'r': // Check readability
status = select(s+1, &socket_fd_set, NULL, NULL, &timeout_timeval);
switch(status)
{
case -1:// SOCKET_ERROR
break;
case 0: // Timeout
break;
default:// Checked sockets
if(FD_ISSET(s, &socket_fd_set))
status = 1;
// Readable
else
status = 0;// Unreadable
}
break;
case 'w': // Check writebility
status = select(s+1, NULL, &socket_fd_set, NULL, &timeout_timeval);
switch(status)
{
case -1:// SOCKET_ERROR
break;
case 0: // Timeout
break;
default:// Checked sockets
if(FD_ISSET(s, &socket_fd_set))
status = 1;
// Writeable
else
status = 0;// Unwriteable
break;
}
break;
case 'x': // Check readability
status = select(s+1, NULL, NULL, &socket_fd_set, &timeout_timeval);
switch(status)
{
case -1:// SOCKET_ERROR
break;
case 0: // Timeout
break;
default:// Checked sockets
if(FD_ISSET(s, &socket_fd_set))
status = 1;
// Readable
else
status = 0;// Unreadable
}
break;
default: // Uknown status
status = -2;
break;
}
return status;
}
#pragma comment (lib, "ws2_32")
#include <stdio.h>
#include <string.h>
#define TIMEOUT 5
//#include "http.h"
FILE *pf;
CRITICAL_SECTION cs;
BOOL flag = true;
int cou = 0;
int SocketStatus(SOCKET s, char x, long timeout);
DWORD WINAPI SndFun(LPVOID pvoid);
int main(int argc, char *argv[])
{
DWORD dTime_start = GetTickCount();
//printf("/n%u/n",GetTickCount() - dTime_start);
//int co;
//scanf("%d", &co);
WORD wVersionRequest = MAKEWORD(2, 2);// [red]这里makeword带的两个参数什么意思啊?? [/red]
WSADATA wsaData;//The WSADATA structure is used to store Windows Sockets
//initialization information returned by a call to the AfxSocketInit global function.
WSAStartup(wVersionRequest, &wsaData);//现在是加载Winsock库,如果WSAStartup()函数返回值为0,说明加载成功,程序可以继续
//往下执行
if (wsaData.wVersion != wVersionRequest)//[red]为什么要看是否相等??[/red] {
printf("the version is wrong");
return 0;//加载的winsock库不成功
}
struct sockaddr_in server_addr;//[red]这里是什么意思??[/red]
memset(&server_addr, 0, sizeof(sockaddr_in));//memset用来对一段内存空间全部设置为某个字符,一般用在对定义的字符串进行初始化为‘ ’或‘/0’;
//这里将所有的sockaddr_in的内存初始化为0
[red]server_addr.sin_addr.S_un.S_addr[/red] = inet_addr("211.83.121.88");
//这个是什么??还有下面的server_addr.sin_family也不知道是什么
server_addr.sin_family = 2;
server_addr.sin_port = htons(80);
//61.152.157.72
int threadnum = 10;
DWORD threadid;
HANDLE hThd[64];
pf = fopen("data_wang.txt", "r");//这个txt文件在哪个文件夹里的?
//做什么用的?是不是记录扫描的结果?
if (pf == NULL)
{
printf("open data wrong/n");
return 0;
}
InitializeCriticalSection(&cs);//初始化一个临界区
for (int i=0;
i<64;
i++)
{
hThd = CreateThread(NULL, 0, SndFun, &server_addr, 0, &threadid);
}
/*FILE *pf;
pf = fopen("wang.txt", "r");
char test1[50];
char test2[10];
fgets(test1, 50, pf);
printf(test1);
fgets(test2, 10, pf);
// the next enter
printf(test2);
fclose(pf);*/
WaitForMultipleObjects(64, hThd, TRUE, INFINITE);
fclose(pf);
printf("/n%u/n",GetTickCount() - dTime_start);
return 1;
}
DWORD WINAPI SndFun(LPVOID pvoid)
{
while (1)
{
char buffer_rcv[65536] = {0};
char buffer_snd[206] = {0};
SOCKET client_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
int timeout = TIMEOUT*1000;
// Send time out
setsockopt(client_socket, SOL_SOCKET, SO_SNDTIMEO,(char *)&timeout,sizeof(timeout));
timeout = TIMEOUT*1000;
// Receive time out
setsockopt(client_socket, SOL_SOCKET, SO_RCVTIMEO,(char *)&timeout,sizeof(timeout));
unsigned long argp = 1; // Set 0:blocking or 1:nonblocking mode socket
ioctlsocket(client_socket, FIONBIO, &argp);
/*struct fd_set socket_fd_set;
struct timeval timeout_timeval;
timeout_timeval.tv_sec = 2;
//wait out!
timeout_timeval.tv_usec = 0;
FD_ZERO(&socket_fd_set);
FD_SET(client_socket, &socket_fd_set);*/
sockaddr *server_addr = (sockaddr *)pvoid;
connect(client_socket, server_addr, sizeof(sockaddr_in));
int status = SocketStatus(client_socket, 'w', TIMEOUT);
//status: 0: timeout;
//....... -1: wrong;
//....... >0: right;
//select(client_socket+1, NULL, &socket_fd_set, NULL, &timeout_timeval);
if (status<=0)
{
printf("sokcetstatus(w) error/n");
closesocket(client_socket);
return 0;
}
/*status = SocketStatus(client_socket, 'r', 0);
if (status<0)
{
printf("sokcetstatus(r) error/n");
closesocket(client_socket);
return 0;
}
if (status>0)
{
recv(client_socket, buffer_rcv, sizeof(buffer_rcv), 0);
printf(buffer_rcv);
}*/
/*status = SocketStatus(client_socket, 'w', TIMEOUT*2);
if (status<=0)
{
printf("sokcetstatus(w) error/n");
closesocket(client_socket);
return 0;
}*/
//strncat(buffer_snd, " HTTP/1.0/x0D/x0A/x0D/x0A", sizeof(buffer_snd));
EnterCriticalSection(&cs);
if (flag) fgets(buffer_snd, 206, pf);
else
goto tt;
if (!strcmp(buffer_snd, "$end$")) {flag = false;
goto tt;}
LeaveCriticalSection(&cs);
strncat(buffer_snd, "/x0D/x0A", sizeof(buffer_snd));
int packet_length = strlen(buffer_snd);
send(client_socket, buffer_snd, packet_length, 0); //
/*fseek(pfile, 0, SEEK_END);
fwrite(buffer_snd, 1, packet_length, pfile);
printf(buffer_snd);
printf("/n");*/
//printf(buffer_snd);
//printf("/n");
status = SocketStatus(client_socket, 'r', 2);
if (status<0)
{
printf("sokcetstatus(r) error/n");
closesocket(client_socket);
return 0;
}
int count = recv(client_socket, buffer_rcv, sizeof(buffer_rcv), 0);
/*fseek(pfile, 0, SEEK_END);
fwrite(buffer_rcv, 1, count, pfile);*/
//printf(buffer_rcv);
//printf("/n");
//if (strstr(buffer_rcv, "DAV: ")!=NULL) printf("the result: have dav hole./n");
//else
printf("the result: not have dav hole./n");
//HTTP_HEAD *http_head;
//http_head = (HTTP_HEAD *)buffer_rcv;
//printf("%d/n",atoi(http_head->status_n));
closesocket(client_socket);
}
tt: LeaveCriticalSection(&cs);
return 1;
}
int SocketStatus(SOCKET s, char x, long timeout)
{
struct timeval timeout_timeval;
timeout_timeval.tv_sec = timeout;
timeout_timeval.tv_usec = 0;
struct fd_set socket_fd_set;
FD_ZERO(&socket_fd_set);
FD_SET(s, &socket_fd_set);
int status;
switch(x)
{
case 'r': // Check readability
status = select(s+1, &socket_fd_set, NULL, NULL, &timeout_timeval);
switch(status)
{
case -1:// SOCKET_ERROR
break;
case 0: // Timeout
break;
default:// Checked sockets
if(FD_ISSET(s, &socket_fd_set))
status = 1;
// Readable
else
status = 0;// Unreadable
}
break;
case 'w': // Check writebility
status = select(s+1, NULL, &socket_fd_set, NULL, &timeout_timeval);
switch(status)
{
case -1:// SOCKET_ERROR
break;
case 0: // Timeout
break;
default:// Checked sockets
if(FD_ISSET(s, &socket_fd_set))
status = 1;
// Writeable
else
status = 0;// Unwriteable
break;
}
break;
case 'x': // Check readability
status = select(s+1, NULL, NULL, &socket_fd_set, &timeout_timeval);
switch(status)
{
case -1:// SOCKET_ERROR
break;
case 0: // Timeout
break;
default:// Checked sockets
if(FD_ISSET(s, &socket_fd_set))
status = 1;
// Readable
else
status = 0;// Unreadable
}
break;
default: // Uknown status
status = -2;
break;
}
return status;
}