Invoke iptables-save and clean up output

This commit is contained in:
Peter J. Holzer 2019-11-02 12:51:08 +01:00 committed by Peter J. Holzer
commit 5331526c2f
1 changed files with 20 additions and 0 deletions

20
iptables-save-clean Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/perl
use v5.22;
use warnings;
my $iptables = `/sbin/iptables-save`;
my %tables = ();
while ($iptables =~ /^\*(\w+)\n(.*?)\nCOMMIT$/smg) {
say STDERR "found $1";
my $table = $1;
my $rules = $2;
$rules =~ s/^:(\w+ \w+) \[\d+:\d+\]$/:$1 [0:0]/smg; # set counters to 0
$tables{$table} = $rules;
}
for my $table (sort keys %tables) {
say "*", $table;
say $tables{$table};
say "COMMIT";
}