Which port is designed to tell you which app is using a specified port ether with UTP or TCP. This is designed to work on MacOS only.
Add the above function to your startup script i.e. ~/.profile
or your ~/.zshrc
. Consult the documentation for your shell
if you aren't using bash
or zsh
.