Created
May 14, 2016 21:09
-
-
Save StudioEtrange/94d0244d99dd77d88142d97af71b2e6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
my $numArgs = $#ARGV + 1; | |
my @types = qw/nat mangle filter/; | |
if ($numArgs > 0) {@types = @ARGV;} | |
$SIG{INT} = sub{print "\e[?25h\e[u"; exit}; | |
print "\e[40;37m\e[2J\e[?25l"; | |
while (1) { | |
print "\e[0;0H"; | |
my %output = map {$_ => scalar `iptables -t $_ -L -v -Z`} @types; | |
foreach my $type (@types) { | |
print "\e[01;34m------", uc($type), '-' x (73 - length($type)), "\n"; | |
$output{$type} =~ s/ pkts[^\n]*\n(\n|Zeroing)/$1/gs; | |
foreach my $line (split /\n/, $output{$type}) { | |
next if $line =~ m/^Zeroing/ || $line eq ''; | |
print $line =~ m/^\s*(\d+)/ || $line =~ m/(\d+) packets/ | |
? ($1 > 0 | |
? ($line =~ m/DROP|DENY|REJECT/ | |
? "\e[01;40;31m" | |
: "\e[01;40;32m") | |
: "\e[00;40;37m") | |
: "\e[00;40;33m"; | |
print "\e[K$line\e[01;40;37m\n" | |
} | |
} | |
print "\e[s"; | |
sleep 1 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment