(no subject)

Jan 03, 2006 20:04



----------------------------------------------------------------------------------------
ceberus:/etc/cron.daily# cat iptable_stamp

Daily Cron Script
----------------------------------------------------------------------------------------

#!/bin/bash

fname="iptables_report.`date +%Y%m%d%H%M%S`.html"

iptables_report_web.sh &> "/usr/local/var/log/$fname"
cp "/usr/local/var/log/$fname" "/usr/local/tmp/"
ftp -n ingenuity.dyndns.org < /usr/local/etc/ureport.txt &> /dev/null
rm "/usr/local/tmp/$fname"

----------------------------------------------------------------------------------------
ceberus:/usr/local/bin# cat /usr/local/etc/ureport.txt

FTP Control Script
----------------------------------------------------------------------------------------

quote user [insert username here]
quote pass [insert password here]
cd htdocs
cd stats
prompt
lcd /usr/local/tmp
mput iptable*

----------------------------------------------------------------------------------------
ceberus:/usr/local/bin# cat iptables_report_web.sh

Converts the "regular" text report to html
----------------------------------------------------------------------------------------
#!/bin/bash

cat /usr/local/etc/header.html;
iptables_report.sh | sed "s/$/
/g"; #add
s to end of lines
cat /usr/local/etc/tail.html

----------------------------------------------------------------------------------------
ceberus:/usr/local/bin# cat iptables_report.sh

Outputs the text report
----------------------------------------------------------------------------------------
#!/bin/bash

echo "Total: `iptables_bytesforwarded.sh | sum.sh | cmb.sh` MB"
echo "Zeus: `iptables_bytesforwarded_zeus.sh | sum.sh | cmb.sh` MB"
echo "Artemis: `iptables_bytesforwarded_artemis.sh | sum.sh | cmb.sh` MB"
echo "Ares: `iptables_bytesforwarded_ares.sh | sum.sh | cmb.sh` MB"
echo "Aphrodite: `iptables_bytesforwarded_aphrodite.sh | sum.sh |cmb.sh` MB"
echo "Apollo: `iptables_bytesforwarded_apollo.sh | sum.sh |cmb.sh` MB"
ceberus:/usr/local/bin#

----------------------------------------------------------------------------------------
ceberus:/usr/local/bin# cat iptables_bytesforwarded.sh

Script outputs the bytecount for each rule. Run for output
----------------------------------------------------------------------------------------

iptables-save -c |grep FORWARD|grep "^\["|cut -b 2-|cut -d ":" -f 2|cut -d "]" -f 1

----------------------------------------------------------------------------------------
ceberus:/usr/local/bin# cat sum.sh

Script to sum the output from bytesforwarded
----------------------------------------------------------------------------------------

#!/bin/bash

read line
let n=0
while [ -n "$line" ]
do
let n=n+line

read line
done

echo "$n"

----------------------------------------------------------------------------------------
ceberus:/usr/local/bin# cat cmb.sh

Rough conversion to megabytes, change the exponent of 1024 for GB/TB
----------------------------------------------------------------------------------------

#!/bin/bash
read line
echo "$line/(1024^2)"|bc

----------------------------------------------------------------------------------------
ceberus:/usr/local/bin# cat iptables_bytesforwarded_zeus.sh

Bytes forwarded for an individual machine. You could get the ip
address from iptables-save -c and use dns to resolve their names.
Infact it would be a better solution then generating them all individually
although more complicated. Whatever. Do what you will, this works
for my network.
----------------------------------------------------------------------------------------

iptables-save -c |grep FORWARD|grep "192.168.1.101"|grep "^\["|cut -b 2-|cut -d ":" -f 2|cut -d "]" -f 1

----------------------------------------------------------------------------------------
Example html output. You can get the header and footer from here.
----------------------------------------------------------------------------------------

IPTables Report - Olympus

IPTables Report - Olympus

Total: 16774 MB

Zeus: 3719 MB

Artemis: 44 MB

Ares: 263 MB

Aphrodite: 12373 MB

Apollo: 372 MB

Previous post Next post
Up