#!/usr/bin/perl
#
# See http://www.devco.net/archives/2005/02/23/ipfw_rule_counters_via_snmpd.php

$ipfw = "/sbin/ipfw";
$ipfwOptions = "show | grep count";

@ipfw = `$ipfw $ipfwOptions`;

$max = 0;

foreach $rule (@ipfw) {
	if ($rule =~ /^(\d+)\s+\d+\s+(\d+)/) {
		$rule = $1;
		$bytes = $2;

		$rule =~ s/^0+//;

		if ($rule gt $max) {
			$max = $rule;
		}

		$rules[$rule] = $bytes;
	}
}

for ($i = 1; $i <= $max; $i++) {
	if ($rules[$i]) {
		print ("$rules[$i]\n");
	} else {
		print ("0\n");
	}
}
