commit 5331526c2f263508dc5f008fd303ede673409e81 Author: Peter J. Holzer Date: Sat Nov 2 12:51:08 2019 +0100 Invoke iptables-save and clean up output diff --git a/iptables-save-clean b/iptables-save-clean new file mode 100755 index 0000000..abc3b13 --- /dev/null +++ b/iptables-save-clean @@ -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"; +}