Skip to content

Instantly share code, notes, and snippets.

@rkitover
Created September 7, 2024 05:42
Show Gist options
  • Save rkitover/874fe9d3f2e0d8605dc883fbf2127e3a to your computer and use it in GitHub Desktop.
Save rkitover/874fe9d3f2e0d8605dc883fbf2127e3a to your computer and use it in GitHub Desktop.
List open ports shell function
ports() {
(
echo 'PROC PID USER x IPV x x PROTO BIND PORT'
(
sudo lsof +c 15 -iTCP -sTCP:LISTEN -P -n | tail -n +2
sudo lsof +c 15 -iUDP -P -n | tail -n +2 | egrep -v ' (127\.0\.0\.1|\[::1\]):'
) | sed -E 's/ ([^ ]+):/ \1 /' | sort -k8,8 -k5,5 -k1,1 -k10,10n
) | awk '{ printf "%-16s %-6s %-9s %-5s %-7s %s:%s\n",$1,$2,$3,$5,$8,$9,$10 }'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment