From 5331526c2f263508dc5f008fd303ede673409e81 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sat, 2 Nov 2019 12:51:08 +0100 Subject: [PATCH] Invoke iptables-save and clean up output --- iptables-save-clean | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 iptables-save-clean 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"; +}