Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I am sending a packets from client machine to server machine. I have 4 dynamic fields i.e. source IP address ,Source Port , Destination IP address and Destination Port All four fields are calling from file. It means every times generating new IP packets which have different IP addresses and Ports. Question is that, For example If I want to send the 100,000 packets per second for the duration of 10 seconds.So my total send packets is 1 Million. But they are sending not more than 26 thousands. I am using one variable DIM...for suppose I change this field like that $dim=1; instead of $dim= scalar(@lines); then it is perfectly work and send 1 Million Packets(but everytime same packets which is not my requirement). Itz means my program can generate 1 Million packets. I want to generate the different packets .Please help me where I am lacking???

#! /usr/bin/perl -s use Net::RawSock; use NetPacket::IP; use NetPacket::TCP; use Time::HiRes qw(usleep gettimeofday tv_interval); use feature qw/say/; use Benchmark; if(!defined $n or !defined $secs ) { print "Usage: ./packgen.pl -n=<number of packets/sec> -secs=< +number of seconds> \n"; exit; } print "\nCreating Packets ...."; open (FILE, '/home/tahir/Downloads/packet_generator.txt'); chomp (@lines = (<FILE>)); close(FILE); ## Create IP my $ip_obj = NetPacket::IP->decode(''); ## Init IP $ip_obj->{ver} = 4; $ip_obj->{hlen} = 5; $ip_obj->{tos} = 0; $ip_obj->{id} = 0x1d1d; $ip_obj->{ttl} = 0x5a; $ip_obj->{flags} = 2; $ip_obj->{len} = 84; ## Create TCP my $tcp_obj = NetPacket::TCP->decode(''); ## Init TCP $tcp_obj->{hlen} = 5; $tcp_obj->{winsize} = 0x8e30; $tcp_obj->{seqnum} = 0xFFFF; $tcp_obj->{acknum} = 0xCCCC; $tcp_obj->{flags} = SYN; $tcp_obj->{data} =ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn; ## Assemble $ip_obj->{proto} = 6; $ip_obj->{data} = $tcp_obj->encode($ip_obj); $num =0; for ($num = 0; $num<=@lines; $num++) { $line=$lines[$num]; #for every line in the lines #build packet my($sip, $sport, $dip, $dport) = split(/\s+/, $line); + $ip_obj->{src_ip} = $sip; $tcp_obj->{src_port} = $sport; $ip_obj->{dest_ip} = $dip; $tcp_obj->{dest_port} = $dport; #print ": $sip\t"; #print ": $sport\t"; #print " : $dip\t"; #print ": $dport\n"; ## Create RAW @packets[$num] = $ip_obj->encode; #say $lines[$j]; #add packet to a vector of packets #end for #Now we have an array of packets } #you want n pkt/sec for 10 seconds, so #you want n/1000 pkt per 1/1000 sec $num=0; $count = 0; $pkts_per_ms = $n / 1000; $start = time(); #[Time::HiRes::gettimeofday]; $dim= scalar(@lines); # $TEST=$packets[0]; while ( ((time()-$start)<($secs)) || ($count < ($n*$secs))) { $before = [Time::HiRes::gettimeofday]; for ($i=$pkts_per_ms;$i>0;$i--) { $num=($num+1)% $dim ; #if now packets is the array of packets,you will send Net::RawSock::write_ip($packets[$num]); # Net::RawSock::write_ip($TEST); } while (tv_interval($before)<0.001) { #print tv_interval($before), " "; } $count = $count + $pkts_per_ms; } print "TIME: ", time()-$start, "\n"; #print "You took ", tv_interval($start), " seconds for sending $co +unt packets.\n"; print "You took ", time() - $start, " seconds for sending $count p +ackets.\n";

In reply to Re^2: Simple Construction of a RAW TCP/IP Packet. by tahirfattani
in thread Simple Construction of a RAW TCP/IP Packet. by cleen

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-24 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found