Question

  • Creator
    Topic
  • #3968390

    Who is listening on a given TCP port on Mac OS X?

    by embersmoloch.0n ·

    Tags: ,

    Hi

    On Linux, I can use netstat -pntl | grep $PORT or fuser -n tcp $PORT to find out which process (PID) is listening on the specified TCP port. How do I get the same information on Mac OS X?

You are posting a reply to: Who is listening on a given TCP port on Mac OS X?

The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our Community FAQs for details. All submitted content is subject to our Terms of Use.

All Answers

  • Author
    Replies
    • #3968391
      Avatar photo

      Re: port

      by kees_b ·

      In reply to Who is listening on a given TCP port on Mac OS X?

      Do you mean that what https://www.lifewire.com/using-netstat-command-on-mac-4176069 says doesn’t work?

    • #3974205

      Reply To: Who is listening on a given TCP port on Mac OS X?

      by embersmoloch.0n ·

      In reply to Who is listening on a given TCP port on Mac OS X?

      Personally I’ve end up with this simple function in my ~/.bash_profile:

      listening() {
      if [ $# -eq 0 ]; then
      sudo lsof -iTCP -sTCP:LISTEN -n -P
      elif [ $# -eq 1 ]; then
      sudo lsof -iTCP -sTCP:LISTEN -n -P | grep -i –color $1
      else
      echo “Usage: listening [pattern]”
      fi
      }
      Then listening command gives you a listing of processes listening on some port and listening smth greps this for some pattern.

      Having this, it’s quite easy to ask about particular process, e.g. listening dropbox, or port, e.g. listening 22.

      lsof command has some specialized options for asking about port, protocol, process etc. but personally I’ve found above function much more handy, since I don’t need to remember all these low-level options. lsof is quite powerful tool, but unfortunately not so comfy to use.

Viewing 1 reply thread