|
Packit |
667938 |
#!/usr/bin/perl
|
|
Packit |
667938 |
# iptables-accounting .9
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# Author: Vern Gill <vgill@technologist.com>
|
|
Packit |
667938 |
# Date: March 9, 2001
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# Adapted from code used in ipchainacc
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# ipchainacc 1.1.0
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# Author: John Lange john@darkcore.net
|
|
Packit |
667938 |
# Date : September 12, 2000
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# The command takes one argument:
|
|
Packit |
667938 |
# Argument: what filter do you want to view
|
|
Packit |
667938 |
# I.E. iptables-accounting filter
|
|
Packit |
667938 |
# iptables-accounting nat
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# Also, you can check bytes or packets. Check the $bytec below
|
|
Packit |
667938 |
# and the text above it for details
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# This command must return 4 lines of output:
|
|
Packit |
667938 |
# Line 1 : current state of the 'incoming bytes counter'
|
|
Packit |
667938 |
# Line 2 : current state of the 'outgoing bytes counter'
|
|
Packit |
667938 |
# Line 3 : string, telling the uptime of the target.
|
|
Packit |
667938 |
# Line 4 : string, telling the name of the target.
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# To add more counters, just edit the commented out if lines
|
|
Packit |
667938 |
# below. For instance, to count the filter table and the
|
|
Packit |
667938 |
# INPUT chain, just change the elsif to filter, and the
|
|
Packit |
667938 |
# $inrule to INPUT
|
|
Packit |
667938 |
# Share and enjoy
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# edit for your system
|
|
Packit |
667938 |
|
|
Packit |
667938 |
$iptables='/usr/local/sbin/iptables'; # path to iptables
|
|
Packit |
667938 |
$host=`/bin/hostname --fqdn`; # local hostname (for information
|
|
Packit |
667938 |
only)
|
|
Packit |
667938 |
|
|
Packit |
667938 |
$table = $ARGV[0];
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if ( $table =~ /^filter/i ) {
|
|
Packit |
667938 |
$inrule='FORWARD';
|
|
Packit |
667938 |
$outrule='OUTPUT';
|
|
Packit |
667938 |
} elsif ( $table =~ /^nat/i ) {
|
|
Packit |
667938 |
$inrule='PREROUTING';
|
|
Packit |
667938 |
$outrule='POSTROUTING';
|
|
Packit |
667938 |
} elsif ( $table =~ /^mangle/i ) {
|
|
Packit |
667938 |
$inrule='PREROUTING';
|
|
Packit |
667938 |
$outrule='OUTPUT';
|
|
Packit |
667938 |
#} elsif ( $table =~ /^table-name-here/i ) {
|
|
Packit |
667938 |
# $inrule='CHAIN-NAME-HERE';
|
|
Packit |
667938 |
# $outrule='OTHER-CHAIN-NAME';
|
|
Packit |
667938 |
#} elsif ( $table =~ /^table-name-here/i ) {
|
|
Packit |
667938 |
# $inrule='CHAIN-NAME-HERE';
|
|
Packit |
667938 |
# $outrule='OTHER-CHAIN-NAME';
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# What should we graph? packet counters = 4, bytes = 6
|
|
Packit |
667938 |
# If you used the ipchainacc script before and you want to keep
|
|
Packit |
667938 |
counting
|
|
Packit |
667938 |
# packets, then set this to 4. If you would rather do the
|
|
Packit |
667938 |
# sensible thing and count bytes, then set this to 6. If you change
|
|
Packit |
667938 |
# from one to the other, then you should delete all the previous
|
|
Packit |
667938 |
# history since it will be meaningless.
|
|
Packit |
667938 |
$bytec=6;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
## -- don't edit below here ----
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# fetch the status from iptables
|
|
Packit |
667938 |
$_=`$iptables -t $table -L $inrule -v -n -x | grep Chain`;
|
|
Packit |
667938 |
@in_bytes = split;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
$_=`$iptables -t $table -L $outrule -v -n -x | grep Chain`;
|
|
Packit |
667938 |
@out_bytes = split;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# uptime of the machine
|
|
Packit |
667938 |
open(UPTIME,"uptime |cut -b 13-27|");
|
|
Packit |
667938 |
$upTime=<UPTIME>;
|
|
Packit |
667938 |
close(UPTIME);
|
|
Packit |
667938 |
chop $upTime;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# 4 lines of output only.
|
|
Packit |
667938 |
printf "$in_bytes[$bytec]\n$out_bytes[$bytec]\n$upTime\n$host";
|