There are a few commands that you can make use of to list all the open ports using the Mac Terminal.
Example 1: Using the netstat
command
% netstat -an | grep LISTEN
tcp6 0 0 *.50019 *.* LISTEN
tcp4 0 0 *.50019 *.* LISTEN
tcp6 0 0 ::1.42050 *.* LISTEN
tcp4 0 0 127.0.0.1.3306 *.* LISTEN
tcp4 0 0 127.0.0.1.33060 *.* LISTEN
tcp6 0 0 *.5000 *.* LISTEN
tcp4 0 0 *.5000 *.* LISTEN
tcp6 0 0 *.7000 *.* LISTEN
tcp4 0 0 *.7000 *.* LISTEN
We have piped this command with grep
to display only the ports that are open, which are displayed with the text LISTEN
Example 2: Using the lsof
command
lsof stands for List Open Files, you can use this command to display all the open network connections as well.
% lsof -i -n
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
loginwind 155 c2ctechtv 5u IPv4 0xb5bd64810edd3853 0t0 UDP *:*
rapportd 415 c2ctechtv 8u IPv4 0xb5bd6494400aecab 0t0 TCP *:50019 (LISTEN)
rapportd 415 c2ctechtv 10u IPv4 0xb5bd64810ecdb453 0t0 UDP *:*
ControlCe 433 c2ctechtv 5u IPv4 0xb5bd6494400a9db3 0t0 TCP *:afs3-fileserver (LISTEN)
ControlCe 433 c2ctechtv 14u IPv4 0xb5bd64810ecd1453 0t0 UDP *:*
WiFiAgent 462 c2ctechtv 3u IPv4 0xb5bd64810ecf5053 0t0 UDP *:*
identitys 470 c2ctechtv 17u IPv4 0xb5bd64810edd2053 0t0 UDP *:*
sharingd 479 c2ctechtv 16u IPv4 0xb5bd64810ecd2c53 0t0 UDP *:*
OneDrive 545 c2ctechtv 19u IPv4 0xb5bd6494400ad61b 0t0 TCP 192.168.0.105:50023->20.198.118.190:https (ESTABLISHED)
OneDrive 545 c2ctechtv 61u IPv4 0xb5bd6494400ad61b 0t0 TCP 192.168.0.105:50023->20.198.118.190:https (ESTABLISHED)
mysqld 687 c2ctechtv 18u IPv4 0xb5bd6494400abf8b 0t0 TCP 127.0.0.1:33060 (LISTEN)
mysqld 687 c2ctechtv 20u IPv4 0xb5bd6494400acad3 0t0 TCP 127.0.0.1:mysql (LISTEN)
Microsoft 742 c2ctechtv 22u IPv6 0xb5bd648aa7b5bf93 0t0 TCP [::1]:42050 (LISTEN)
Google 903 c2ctechtv 19u IPv4 0xb5bd64810ecd2453 0t0 UDP 192.168.0.105:62576->104.21.91.10:https
Google 903 c2ctechtv 22u IPv4 0xb5bd64810edcd053 0t0 UDP 192.168.0.105:51646->142.250.199.130:https
Google 903 c2ctechtv 36u IPv4 0xb5bd64810ecc8853 0t0 UDP 192.168.0.105:59606->35.190.0.66:https
chronod 2882 c2ctechtv 11u IPv6 0xb5bd64810ecd8c53 0t0 UDP *:57599
![List of All Open Ports using Mac Terminal Example List of All Open Ports using Mac Terminal Example](https://code2care.org/howto/list-all-open-ports-mac-terminal/images/List of All Open Ports using Mac Terminal Example.jpg)
Facing issues? Have Questions? Post them here! I am happy to answer!
Author Info:
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
More Posts related to MacOS,
- Fix: grunt: command not found (Mac/Windows)
- AppleScript Example with TextEdit
- How to copy Password of Wifi on your Mac
- Install OpenJDK Java (8/11/17) versions using brew on Mac (Intel/M1/M2)
- How to check if a port is in use using terminal [Linux or macOS]
- Cut, Copy and Paste Keyboard Shortcuts on Mac Keyboard
- [macOS] NetBeans IDE cannot be installed. Java (JRE) found on your computer but JDK XX or newer is required.
- How to Remove Widgets from macOS Sonoma 14 Desktop
- Turn off Auto-Capitalization on macOS Ventura 13
- How to Go To /usr/local/bin on Mac Terminal?
- How to Open TextEdit on Mac
- Mac: How to Open Android Studio from Terminal
- How to change the default location of Mac Screenshot
- Display Seconds in Digital Clock on Mac Menu Bar [macOS]
- How to install homebrew (brew) on M1 Mac
- Must Know Homebrew Commands for Mac/Linux Users
- Steps to Uninstall Roblox on Mac (macOS)
- How to change the System Settings Sidebar icon size Mac Ventura 13
- How to set Out Of Office (OOO) on Outlook for Mac [Updated 2023]
- Trigger Notification Center Message using Mac Terminal Command
- [fix] macOS Ventura - Python3 xcrun: error: invalid active developer path missing xcrun at CommandLineTools
- How to Install Rust Language on Mac (macOS)
- How to minimize all Windows in Mac
- Display ls command file sizes in KB (kilobytes) MB (megabytes) or GB (gigabytes) [Linux/macOS]
- How to make TextEdit the default text Editor on Mac
More Posts:
- Fix: Spring Boot REST HTTP Status 415 - Unsupported Media Type Error - Java
- Opening mac Terminal - MacOS
- URL Encode cURL HTTP GET\POST Data with Examples - cURL
- Fix Git: Warning: could not find UI helper GitHub.UI on Windows - Git
- What is the Default Admin user and Password for Jenkins - Linux
- Must Know Homebrew Commands for Mac/Linux Users - MacOS
- Setting up Spring Boot 3 + Maven + MySQL + JDBC Example - Java
- How to hide lines in Notepad++ - NotepadPlusPlus