Created
July 25, 2019 15:39
-
-
Save larzconwell/173d4e37b178bdf50c9b8d909c5b5cff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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