Am 26.03.2017 um 21:21 schrieb Dirk Stöcker:
> Checking my current logfiles of the last few days and stripping all duplicate 
> entries (IP addresses or domain names indicate they are same) I get following 
> results (for outgoing TLS connections):
> 
> Server 1: 5 / 24 == 17% IPv6
> Server 2: 12 / 137 = 8% IPv6
> 
> Note, that all of the IPv6 servers are also in the IPv4 list because of the 
> way postfix handles sending.
> 
> The percentage of IPv6 connections is much higher, as many mails go the IPv6 
> hosts (especially because of google hosts), whereas all the others get only 
> little mail. Probably stats are lower for non TLS connections, but who cares 
> about these...
> 
> So while a suggestion not to care about IPv6 may have been valid in 2014. It 
> is simply wrong in 2017.
> 
> P.S. For server 2 simply counting IP addresses it is 78 / 330 = 19% IPv6.


Hello,

Dirk remind me I wrote a script years ago to gather delivery statistic by 
inet_protocol.
It happily mix german and english, misses documentation, may not be perfect at 
all but give a quick view on your delivery profile.

cat /var/log/mail.log | postdelivery_via_v4_or_v6

Andreas
#!/usr/bin/perl

# sca, 20130812
# cat maillog | $0
# Auflistung, wieviel Mails via v4 oder v6 verschickt werden

use warnings;
use strict;
use Getopt::Long;

my ($name,$ip,$port,$proto);
my %opt     = ();
my %result  = (
  'total'   => 0, # Anzahl aller Zeilen mit "relay="
  'none'    => 0, # Anzahl der Zeilen mit "relay=none"
  'ignore'  => 0, # ignorierte Relays
  'match'   => 0, # Zeilen, die auf den Regex zum separieren von Name,IP und 
Port passen
  'err'     => 0, # Fehler: Zeilen, die nicht auf den regex passen
  '4'       => 0, # erkannte v4
  '6'       => 0, # erkannte v6
  'noproto' => 0, # Fehler: weder v4 noch v6 erkannt
);

Getopt::Long::Configure('no_ignore_case');
GetOptions(\%opt, 'verbose|v', 'debug|d', 'nosummary|n', 'ignore-host=s@') or 
exit(1);

# compile --ignore-host regexps
if(defined $opt{'ignore-host'}) {
  for my $ih (@{$opt{'ignore-host'}}) {
    push @{$opt{'ignore-host-re'}}, qr{\brelay=[^\s,]*$ih}i;
  }
  if ($opt{debug}) {
    foreach my $i (@{$opt{'ignore-host-re'}}) {
      print "DEBUG: ignore-host-re: $i\n";
    }
  }
}

# loop on stdin
while (<>) {

  next unless /\/smtp\[/;
  next unless /\,\srelay=/;

  $result{total}++;

  if (/\,\srelay=none,\s/) {
    $result{none}++;
    next;
  }

  if(defined $opt{'ignore-host-re'}) {
    my $ignore;
    for my $ih (@{$opt{'ignore-host-re'}}) {
      if ($_ =~ $ih) {
        print "DEBUG: ignoring: $_" if $opt{debug};
        $ignore = 1;
      }
    }
    if ($ignore) {
      $result{ignore}++;
      next;
    }
  }

  if ((($name,$ip,$port) = $_ =~ /\,\srelay=([\d\w\.-]+)\[(.*)\]\:(\d+)\,/) == 
3) {

    $result{match}++;
    if ($ip =~ /\./) {
      $proto = '4';
      $result{4}++;
    } elsif ($ip =~ /\:/) {
      $proto = '6';
      $result{6}++;
    } else {
      $proto = 'noproto';
      $result{noproto}++;
    }
    printf "%s, %s, %s, %s\n", $proto, $name, $ip, $port if $opt{verbose};
  } else {
    print STDERR "PROGRAMMERS ERROR: regex does not match: $_\n";
    $result{err}++;
  }
}

if (!$opt{nosummary}) {
  if ($opt{verbose}) {
    print "\nSummary\n";
    print "=======\n";
  }
  printf "Relay-Zeilen: % 7i = 100.0 %%\n", $result{'total'};
  if (0 != $result{'total'}) { # avoid illegal division by zero
    printf "  Relay=none: % 7i = %5.1f %%\n", $result{'none'}, 
$result{'none'}/$result{'total'}*100;
    if ($result{'ignore'}) {
      printf "     ignored: % 7i = %5.1f %%\n", $result{'ignore'}, 
$result{'ignore'}/$result{'total'}*100;
    }
  }
  print "\n";
  printf "      Relays: % 7i = 100.0 %%\n", $result{'match'};
  if (0 != $result{'match'}) { # avoid illegal division by zero
    printf "        ipv4: % 7i = %5.1f %%\n", $result{'4'}, 
$result{'4'}/$result{'match'}*100;
    printf "        ipv6: % 7i = %5.1f %%\n", $result{'6'}, 
$result{'6'}/$result{'match'}*100;
    printf "        none: % 7i\n", $result{'noproto'} if (0 != 
$result{'noproto'});
    printf "         err: % 7i\n", $result{'err'} if (0 != $result{'err'});
  }
}

exit(0);

__END__

=head1 NAME

postdelivery_via_v4_or_v6 - summary about used inet_protocols

=head1 SYNOPSIS

B<postdelivery_via_v4_or_v6> [I<options>...]

=cut

Reply via email to