Skip to content

Instantly share code, notes, and snippets.

@larzconwell
Created Jul 25, 2019
Embed
What would you like to do?
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