https://github.com/patatetom/iptables_sorted_colored
Sort and color output of iptables -S
https://github.com/patatetom/iptables_sorted_colored
bash bash-script firewall iptables iptables-rules sublime-syntax sublime-text
Last synced: about 1 month ago
JSON representation
Sort and color output of iptables -S
- Host: GitHub
- URL: https://github.com/patatetom/iptables_sorted_colored
- Owner: patatetom
- Created: 2019-07-22T09:07:17.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-02T08:07:06.000Z (over 6 years ago)
- Last Synced: 2025-01-14T05:28:39.023Z (over 1 year ago)
- Topics: bash, bash-script, firewall, iptables, iptables-rules, sublime-syntax, sublime-text
- Language: Shell
- Size: 116 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# iptables -S | sorted | colored
Sort and color the output of `iptables --list-rules`

## implementation
### iptsort
- download the [bash script](iptsort) 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](https://github.com/sharkdp/bat)
- build the necessary tree structure with `mkdir -p ~/.cache/bat/ ~/.config/bat/syntaxes/`
- download the [lexer](iptables.sublime-syntax) 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 :
```bash
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 :
```bash
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](https://eeyo.io/iro/).