В файле конфигурации exim пишем: log_file_path = /var/log/exim/exim-%s-%D.log
log_selector = +delivery_size +sender_on_delivery +received_recipients
В файл /var/db/ukr_net ложим список украинских сетей
И собствено скрипт для подсчета трафика с разделением на украинский и мировой:
#!/usr/bin/perl -w
my ($nmin, $nmax) = (32,0);
open UKRNETS, "/var/db/ukr_net";
while (<UKRNETS>) {
s/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\/([0-9]+)$//;
$UkrIPs{substr(substr(unpack("B32", pack("N", $1)),24).substr(unpack("B32", pack("N", $2)),24).substr(unpack("B32", pack("N", $3)),24).substr(unpack("B32", pack("N", $4)),24),0,$5)}="$1.$2.$3.$4\/$5";
$nmin = $5 if $5 < $nmin;
$nmax = $5 if $5 > $nmax;
}
close UKRNETS;
open TRAFF, '/var/log/exim/exim-main-20060122.log';
while (<TRAFF>) {
my ($mail_from,$mail_to,$ip,$bytes_in,$bytes_out);
if (/^[0-9-]+ [0-9:]+ [A-Za-z0-9]{6}-[A-Za-z0-9]{6}-[A-Za-z0-9]{2} <= ([^\@]+@[A-Za-z0-9-.]+).* H=.*\[([0-9.]+)\].* S=([0-9]+).* for ([^\@]+@[A-Za-z0-9-.]+)$/) {
$mail_1=$1;
$mail_2=$4;
$ip=$2;
$bytes_in=$3;
$bytes_out=0;
} elsif (/^[0-9-]+ [0-9:]+ [A-Za-z0-9]{6}-[A-Za-z0-9]{6}-[A-Za-z0-9]{2} [\=\-\*]\> ([^\@]+@[A-Za-z0-9-.]+).* F=\<([^\@]+@[A-Za-z0-9-.]+)\>.* T=remote_smtp S=([0-9]+).* H=.*\[([0-9.]+)\].*/) {
$mail_1=$2;
$mail_2=$1;
$ip=$4;
$bytes_in=0;
$bytes_out=$3;
}
if ((defined($ip)) and ($ip =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)) {
my $ipB=substr(unpack("B32", pack("N", $1)),24)."".substr(unpack("B32", pack("N", $2)),24)."".substr(unpack("B32", pack("N", $3)),24)."".substr(unpack("B32", pack("N", $4)),24);
for ($Ne=$nmax; $Ne>=$nmin; $Ne--) {
my $ipBin=substr($ipB,0,$Ne);
if ($UkrIPs{$ipBin}) {
$m_from{$mail_1}{ukr}{in} +=$bytes_in;
$m_from{$mail_2}{ukr}{in} +=$bytes_in;
$m_from{$mail_1}{ukr}{out}+=$bytes_out;
$m_from{$mail_1}{mir}{in} -=$bytes_in;
$m_from{$mail_2}{mir}{in} -=$bytes_in;
$m_from{$mail_1}{mir}{out}-=$bytes_out;
last;
}
}
$m_from{$mail_1}{mir}{in} +=$bytes_in;
$m_from{$mail_2}{mir}{in} +=$bytes_in;
$m_from{$mail_1}{mir}{out}+=$bytes_out;
}
}
close TRAFF;
my $i=0;
foreach $mails (keys %m_from) {
$i++;
print "$i $mails
in ukr $m_from{$mails}{ukr}{in}
out ukr $m_from{$mails}{ukr}{out}
in mir $m_from{$mails}{mir}{in}
out mir $m_from{$mails}{mir}{out}
";
}
URL:
Обсуждается: http://www.opennet.me/tips/info/971.shtml