Skip to content

Instantly share code, notes, and snippets.

@aflansburg
Created July 1, 2024 21:03
Show Gist options
  • Save aflansburg/5b505b2d9801fdff1b629b806fb306de to your computer and use it in GitHub Desktop.
Save aflansburg/5b505b2d9801fdff1b629b806fb306de to your computer and use it in GitHub Desktop.
"wport" - tells you ports that are LISTENing or checks a specific port
# add to ~/.zhsrc
# run source ~/.zshrc
# run w/ `wport` or `wport <port>`
function wport(){
if [ "$1" = "help" ] || [ "$1" = "-h" ]; then
echo "Usage: wport [port]"
echo "Without a port argument, list all ports that are currently being listened to."
echo
echo "If a port is provided, list only the port that is being listened to."
echo
return
fi
if [ -z "$1" ]; then
lsof -i -P | grep -e "LISTEN"
else
lsof -i -P | grep -e "$1.*LISTEN"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment