Skip to content

Instantly share code, notes, and snippets.

@larzconwell
Created July 25, 2019 15:39
Show Gist options
  • Save larzconwell/173d4e37b178bdf50c9b8d909c5b5cff to your computer and use it in GitHub Desktop.
Save larzconwell/173d4e37b178bdf50c9b8d909c5b5cff to your computer and use it in GitHub Desktop.
ports () {
local items="$(sudo lsof -n -i -P | tr -s " " | cut -d " " -f 2,9,10 | \grep "LISTEN")"
printf "%-10s %-20s %s\n" "PID" "ADDRESS" "COMMAND"
if [[ "${items}" == "" ]]
then
return
fi
while read item
do
pid="$(echo "${item}" | awk '{print $1}')"
addr="$(echo "${item}" | awk '{print $2}')"
cmd="$(ps -o command "${pid}" | sed 1d)"
printf "%-10s %-20s %s\n" "${pid}" "${addr}" "${cmd}"
done <<< "${items}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment