Invoke iptables-save and clean up output
This commit is contained in:
commit
5331526c2f
|
@ -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";
|
||||
}
|
Loading…
Reference in New Issue