See a List of All Open Ports using Mac Terminal

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

    Comments & Discussion

    Facing issues? Have questions? Post them here! We're happy to help!