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
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,
- How to show line numbers in Nano on Mac
- How to install Jupyter Notebook on macOS Sonoma
- How to Disable Remote Management using Mac Terminal
- Test internet speed using macOS Terminal command
- Docker Desktop needs privileged access macOS
- Google Search Hot Trends Screensaver for Mac OS X
- How to do calculations in Mac Terminal
- How to make TextEdit the default text Editor on Mac
- How to Show Full Website Address on Safari for Mac (Ventura/Sonoma)
- The Zsh Shell - Mac Tutorial
- Opening mac Terminal
- How to change the name of your Mac running on macOS Ventura 13
- How to find the Battery Cycle Count on macOS Ventura
- How to set an emoji as Zsh terminal prompt in macOS
- How to access Trash Folder using Mac Terminal Command
- macOS Ventura XCode Command Line Tools Installation
- Hide Bluetooth icon on Mac Menu Bar macOS Ventura 13
- How to run .sh file in Mac Terminal
- Terminal Command to get the list of available shells in macOS
- How to see Storage Information on macOS Ventura
- How to Go To /usr/local/bin on Mac Terminal?
- How to do screen recording on Mac
- How to Find File and Directory Size in Mac Terminal
- Open .bash_profile File in TextEdit using Terminal
- Remove Now Playing icon from macOS Big Sur Menu Bar
More Posts:
- Integrating Android Facebook SDK 3.17.2 Tutorial - Android
- How to delete a Python Virtual Environment - Python
- Change CKEditor Table Properties default width - CKEditor
- Notepad++ is about to exit prompt message - NotepadPlusPlus
- [fix] SharePoint: We only support embedding content from secure websites - SharePoint
- MySQL Query for Schema/Structure of a Table - MySQL
- How to Show Line Numbers in Jupyter Notebook Cells - Python
- Upload Pdf file using PHP Script - PHP