Skip to content

patatetom/iptables_sorted_colored

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

iptables -S | sorted | colored

Sort and color the output of iptables --list-rules

Sorted and colored output

implementation

iptsort

  • download the bash script in /usr/local/bin/
  • after verification, make it executable with chmod +x /usr/local/bin/iptsort
  • try it with iptables -S | iptsort.

bat

  • install (or download it in /usr/local/bin/ if not available for your distribution) the excellent bat
  • build the necessary tree structure with mkdir -p ~/.cache/bat/ ~/.config/bat/syntaxes/
  • download the lexer in ~/.config/bat/syntaxes/
  • rebuild the bat cache with bat cache --build
  • try it with iptables -S | bat.

that's all !

you can now orchestrate the whole thing with iptables -S | iptsort | bat.

trick

you can add this helper in your ~/.bashrc script :

function iptables {
  org=$( which iptables ) || return;
  if [ "${1}" ]
  then
    "${org}" $@
  else
    "${org}" -S | iptsort | bat -p
  fi
}

this following helper can also be very useful :

function ss {
  org=$( which ss ) || return;
  if [ "${1}" ]
  then
    "${org}" $@
  else
    "${org}" -plntu | sed -e 1d -e 's/users:(//g' -e 's/)$//g' | awk '{print $1, $5, $7}' | column -t | bat -pl c
  fi
}

the lexer was partially written using Iro.