We will be testing out some new cisco loadbalancers and firewalls next week, and I thought it would be interesting to write a simple traffic generator to hammer away at them. I wanted something that could spawn off a bunch of child processes that would transmit customized packets to these devices. I came up with the following script using the Parallel::ForkManager and Net::RawIP packages. The script runs, but my test server doesnt seem to be generating as much traffic as I expected. In fact it hardly sends anything at all. I know it is sending some requests because I can see them via tcpdump on my victim server.

Has anyone had any experience writing anything similar to this? Is there anything obvious that sticks out in here?

#==================================================================== # USER DEFINES # global defaults my $def_proto = "icmp"; # default protocol to use my $pattern = 153; # default data pattern to send. + my $num_bytes = 40; # default number number of bytes to send in data +section. my $children = 20; # default number of child processes to spawn my $requests = 50; # default number of requests that each child sends # protocol specific defaults my $prot_ip = { tos => '0', ttl => '30', saddr => '172.16.0.1', }; my $prot_tcp = {source => "33333", dest => "80", urg => "0", ack => "0", psh => "0", rst => "0", syn => "1", fin => "0", }; my $prot_udp = {source => "53", dest => "33333", }; my $prot_icmp = {type => "8", code => "0", }; #======================================= #===================================================================== += # MAIN #------------------- # get data info from user print "number of bytes in data field? [$num_bytes] : "; $input = <STDIN>; chomp ($input); if (($input) && ($input<1501) && ($input>0)) {$num_bytes = $input;} #--------- #------------------- # make data portion of packet my $data = $pattern x $num_bytes; $data = pack("C", $data); #--------- #------------------- # get protocol info from user # get ip info set_ip(); # get upper layer protocol type and info print "tcp, udp, or icmp? [$def_proto] : "; $input = <STDIN>; chomp ($input); if ($input ne "") { if ($input eq "tcp") { $def_proto = "tcp"; set_tcp(); # set prefs for tcp datagram $prot_tcp->{data} = $data; $packet{tcp} = $prot_tcp; } elsif ($input eq "udp") { $def_proto = "udp"; set_udp(); # set prefs for udp datagram $prot_udp->{data} = $data; $packet{udp} = $prot_udp; } else { $def_proto = "icmp"; set_icmp(); # set prefs for icmp datagram $prot_icmp->{data} = $data; $packet{icmp} = $prot_icmp; } } $packet{ip} = $prot_ip; #--------- #------------------- # fork off children and x-mit data my $pm = new Parallel::ForkManager($children); ReadMode 4; # Turn off controls keys print "press any key to quit...\n"; while (not defined (my $key = ReadKey(-1))) { # Forks and returns the pid for the child: my $pid = $pm->start and next; my $pkt_h = new Net::RawIP; $pkt_h->set(\%packet); $pkt_h->send(.25,$requests); $pm->finish; # Terminates the child process } ReadMode 0; # Reset tty mode before exiting print "\n\nwaiting on child processes to stop..."; $pm->wait_all_children; print "...all done...quitting.\n"; #--------- #=======================================

In reply to rawIP traffic generator by dlspinhir

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.