IP packet count at regular intervals of time.

Discussion in 'Perl Misc' started by Cognition Peon, Nov 24, 2003.

  1. Greetings,

    I have been trying to write a program to graph live traffic on a network
    interface. Tk::Graph has been very helpful to create live graphs.

    The important problem, which I am not able to get through or find any good
    help is counting all incoming packets at a specified regular interval.

    I have used Net::pcap and Time::HiRes to write the following program to
    count interface traffic in 0.5 sec intervals of time.

    #!/usr/bin/perl -w

    use strict;
    use English;
    use Net::pcap;
    use Time::HiRes qw (setitimer time ITIMER_REAL);

    my($dev, $pcap_t, $err);

    $dev = Net::pcap::lookupdev(\$err);
    $pcap_t = Net::pcap::eek:pen_live($dev, 1500, 1, 0, \$err);

    my $count = 0;
    sub process_pkt {
    my ( $user_data, $hdr, $pkt ) = @_;
    $count++;
    $SIG{ALRM} = sub { print time, " $count\n"; $count = 0 };
    setitimer(ITIMER_REAL, 0.5, 0.5);
    }

    Net::pcap::loop( $pcap_t, 0, \&process_pkt, "argument");
    Net::pcap::close($pcap_t);


    Perl 5.8 installed on my linux is not configured with threads enabled. The
    output, as shown below, is generated at irregular intervals of time.

    1069646988.25076 3
    1069647025.00529 2
    1069647031.59172 121
    1069647033.06818 7
    1069647037.78875 66

    Any help or pointers towards a good solution will be greatly appreciated.

    Thanks,
    Prakash.

    --
    echo | perl -pe 'y/A-Za-z/N-ZA-Mn-za-m/'

    Sometimes I think the surest sign that intelligent life
    exists elsewhere in the universe is that none of it has
    tried to contact us. -- Bill Watterson "Calvin and Hobbes"
    -------------------------------------
    Printed using 100% recycled electrons
     
    Cognition Peon, Nov 24, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?am9l?=

    Updating IE Page at regular intervals

    =?Utf-8?B?am9l?=, Jan 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    360
    Steve C. Orr [MVP, MCSD]
    Jan 21, 2004
  2. Peter Strøiman
    Replies:
    3
    Views:
    5,881
    Steven Cheng[MSFT]
    Aug 8, 2005
  3. Li Han
    Replies:
    2
    Views:
    515
    bobicanprogram
    Feb 9, 2009
  4. David
    Replies:
    13
    Views:
    863
  5. Gelonida N
    Replies:
    4
    Views:
    919
    Gelonida N
    Sep 11, 2011
Loading...

Share This Page