Skip to content

Instantly share code, notes, and snippets.

@pepoluan
Created January 19, 2026 03:26
Show Gist options
  • Select an option

  • Save pepoluan/c0d16ac8edcd717163b04915801547b8 to your computer and use it in GitHub Desktop.

Select an option

Save pepoluan/c0d16ac8edcd717163b04915801547b8 to your computer and use it in GitHub Desktop.
Show Listener Processes with Detailed Arguments, using `ss` instead of `netstat`
#!/bin/bash
# © 2026, Pandu POLUAN
# SPDX-License-Identifier: MPL-2.0
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
function show_listeners() {
ss -tulpn |
awk '
BEGIN { print "Proto", "IP:Port", "PID", "@@CmdLine" }
match($7, /,pid=([0-9]+)/, ary) { print $1, $5, ary[1], "@@" ary[1] }
' |
column -t |
(
while read -r ln; do
elems=($ln)
pid="${elems[3]/@@/}"
echo -n "${ln%%@@*}"
if [[ $pid = CmdLine ]]; then
echo "CmdLine"
continue
fi
readarray -d $'\0' cmd < /proc/$pid/cmdline
echo "${cmd[*]}"
done
)
}
show_listeners
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment