#!/usr/local/perl
#
# A perl script to count packets on Ethernet and 802.11b networks for network activity visualization projects
# Anthony Townsend, Kurt Starsinic
# Distributed under GPL license
while ()
{
$n = 10;
$packets = 0;
$end = time() + $n;# change to en0 for Ethernet en1 for wireless on Mac
open(TCPDUMP,"/usr/sbin/tcpdump -q -i en1|") or die "Can't open
tcpdump: $!";
while (<TCPDUMP>) {
$packets++;
last if time() > $end;
}close TCPDUMP;
open (OUTFILE, ">/var/tmp/packetcount") or die "Can't open file for writing";
print OUTFILE $packets;
print "Total packets received in last 10 seconds (# written to /var/tmp/packetcount): $packets\n";
}
On Oct 28, 2004, at 11:45 AM, Anthony Townsend wrote:
hi all - another help request
i have a student who needs a short script that will use tcpdump to count the total # of packets heard on a wireless network every N seconds
was able to find this Perl snippet as a start, but need to figure out a way to make it end after N seconds and then output the total # of packets (i.e. the total number of lines), and dump the IP filters and just count all the packets.
open(TCPDUMP,"/usr/sbin/tcpdump -q -i wlan0|") or die "Can't open tcpdump: $!"; for (<TCPDUMP>) { ++$hogcount[0] if /192.168.1.15$/; # hog #1 ++$hogcount[1] if /192.168.1.45$/; # hog #2 }
END { close TCPDUMP; print "Hog 1 had $hogcount[0] packets and Hog 2 had
$hogcount[1]\n"; }
thanks in advance for anyone willing to help
--
NYCwireless - http://www.nycwireless.net/
Un/Subscribe: http://lists.nycwireless.net/mailman/listinfo/nycwireless/
Archives: http://lists.nycwireless.net/pipermail/nycwireless/
-- NYCwireless - http://www.nycwireless.net/ Un/Subscribe: http://lists.nycwireless.net/mailman/listinfo/nycwireless/ Archives: http://lists.nycwireless.net/pipermail/nycwireless/
