├── README.md
└── sss
/README.md:
--------------------------------------------------------------------------------
1 |

2 |
3 | # GNOS Sockets
4 |
5 | List IP sockets
6 |
7 | - auto-sudo
8 | - sane CLI args & defaults
9 | - meaningful color scheme
10 | - searchable sorted output
11 | - shortened addresses (0.0.0.0 -> 0, 127.0.0.1 -> 1)
12 |
13 | ## Usage
14 |
15 | ```
16 | Usage: sss [ options ] [ PATTERN ]
17 |
18 | -4 Display only IPv4 sockets
19 | -6 Display only IPv6 sockets
20 | -t Display only TCP sockets
21 | -u Display only UDP sockets
22 | -l Display only listening sockets
23 | -L Display only non-listening sockets
24 | -s Display short IP
25 | -N Resolve numerics
26 | PATTERN Plain-text match
27 | ```
28 |
29 | If you have the habit of `ss -tupln`, you can use the same with `sss -tupln`, unknown parameters will not disturb the output.
30 |
31 | ## Install
32 | ### APT
33 | Use the repository https://packages.azlux.fr/ and install with `apt update` and `apt install sss`
34 |
35 | ### Manually (no auto-update)
36 | Just copy somewhere in your `$PATH`.
37 |
38 | Depends: `ss` `sed` `awk` `sort` `column` `sudo`.
39 |
--------------------------------------------------------------------------------
/sss:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | # NAME: GNOS sockets
3 | # DESC: Handy ss wrapper
4 | # FEAT: Colors support
5 | # DEPS: ss sed awk sort column sudo
6 | # LICE: WTFPL
7 | # AUTH: elias@gnos.in
8 |
9 |
10 | ########
11 | # FUNC #
12 | ########
13 |
14 | Usage () # $1:RET
15 | {
16 | cat </dev/null ; do
230 | case "$opt" in
231 |
232 | 4) [[ $ipv -eq 6 ]] && ipv=0 || ipv=4 ;;
233 | 6) [[ $ipv -eq 4 ]] && ipv=0 || ipv=6 ;;
234 |
235 | t) [[ $tcp -eq 2 ]] && tcp=3 || tcp=1 ;;
236 | u) [[ $tcp -eq 1 ]] && tcp=3 || tcp=2 ;;
237 |
238 | l) [[ $listen -eq 2 ]] && listen=0 || listen=1 ;;
239 | L) [[ $listen -eq 1 ]] && listen=0 || listen=2 ;;
240 |
241 | N) numeric=0 ;;
242 | s) short=1 ;;
243 |
244 | h) Usage 0 ;;
245 | [?]) Usage 1 ;;
246 | esac
247 | done
248 | shift "$((OPTIND-1))"
249 | [[ $# -gt 1 ]] && Usage 1
250 | pattern=$1
251 | shift
252 |
253 | # USER
254 | if [[ $( id -u ) -ne 0 ]] ; then
255 | sudo "$( readlink -f "$BASH_SOURCE" )" $args && exit
256 | [[ -n $colors ]] && echo -en $cyellow >&2
257 | echo "WARNING: Running unprivileged" >&2
258 | [[ -n $colors ]] && echo -en $creset >&2
259 | fi
260 |
261 | # OPTS
262 | [[ $numeric -eq 1 ]] && opts="$opts --numeric" || opts="$opts --resolve"
263 | case $listen in
264 | 0) opts="$opts --all" ;;
265 | 1) opts="$opts --listen" ;;
266 | esac
267 | case $tcp in
268 | 0) [[ $listen -eq 2 ]] \
269 | && opts="$opts --tcp --udp" \
270 | || opts="$opts --tcp --udp --raw" ;;
271 | 3) opts="$opts --tcp --udp" ;;
272 | 1) opts="$opts --tcp" ; force=tcp ;;
273 | 2) opts="$opts --udp" ; force=udp ;;
274 | esac
275 |
276 |
277 | ########
278 | # MAIN #
279 | ########
280 |
281 | {
282 | # Header
283 | [[ -n $colors ]] && echo -en $cbold
284 | if [[ $listen -eq 1 || $force == "udp" ]] ; then
285 | echo -n USER PROCESS PID PROTO LOCAL STATE
286 | else
287 | echo -n USER PROCESS PID PROTO LOCAL REMOTE STATE
288 | fi
289 | [[ -n $colors ]] && echo -en $creset
290 | echo
291 |
292 | # Data
293 | {
294 | [[ $ipv -eq 4 || $ipv -eq 0 ]] && ss $opts --ipv4 | Fix | Render "$colors" "" "$pattern" "$listen" "$numeric" "$force" "$short"
295 | [[ $ipv -eq 6 || $ipv -eq 0 ]] && ss $opts --ipv6 | Fix | Render "$colors" 6 "$pattern" "$listen" "$numeric" "$force" "$short"
296 | } | sort -n
297 |
298 | } | column -t
299 |
--------------------------------------------------------------------------------