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!
More Posts related to MacOS,
- Clear Screen shortcut macOS Terminal
- What is macOS Ventura?
- [fix] How to Show file extensions on all files on Mac
- How to Find Where Mac Terminal App is Located?
- AutoSave button not working on Office on Mac (Word, Excel or Powerpoint)
- macOS say command text to speech using various voices and languages
- How to change Ping TTL value on macOS
- Open .bash_profile File in TextEdit using Terminal
- How to know the Safari Version on Mac
- How to Copy full Absolute Path of a File on Mac
- 13.0 MacOS Ventura release date
- Enable spell check in Sublime Text (macOS)
- How to Display Analog Clock on Mac Menu Bar
- How to turn off Location Services macOS Ventura 13
- How to Open VS Code on Mac
- Add Bookmark macOS Safari
- How to Fix cd: too many arguments Error in Terminal: A Step-by-Step Guide
- How to install wget on macOS
- Select Line Number TextEdit on Mac
- Strikethrough Text in Excel for Mac
- How to Enable or Disable Dark Mode on macOS Ventura 13
- How to hide or display Wifi icon in macOS Bug Sur Menu Bar
- How to install Yarn on Mac (macOS)
- How to fix command not found brew (bash, zsh) on macOS Terminal
- How to Schedule Mails in macOS Ventura
More Posts:
- What does chmod +x filename command do? - Linux
- Minecraft Java Edition - Java
- All directional arrows codes for HTML - Html
- How to migrate Kaizala to Microsoft Teams - Teams
- Display Output in Java Console as a Table - Java
- How to check if an element is hidden using jQuery code? - jQuery
- SQLite with Android Easy to Understand Tutorial that covers Select, Insert, Update and Delete - Android
- Add imports in eclipse shortcut key combinations - Eclipse