#linux #ports You can check open ports using various tools across different operating systems. Here’s how to do it on the most popular ones: Linux, macOS, and Windows. ### Linux #### 1. `netstat` ```sh sudo netstat -tuln ``` - `-t` displays only TCP connections. - `-u` displays only UDP connections. - `-l` shows only listening ports. - `-n` displays numerical addresses and ports. #### 2. `ss` ```sh sudo ss -tuln ``` - `-t` displays only TCP connections. - `-u` displays only UDP connections. - `-l` shows only listening ports. - `-n` displays numerical addresses and ports. #### 3. `lsof` ```sh sudo lsof -i -P -n | grep LISTEN ``` - `-i` shows network files. - `-P` displays ports in numerical format. - `-n` displays IP addresses in numerical format. #### 4. `nmap` ```sh sudo nmap -sT -O localhost ``` - `-sT` performs a TCP connect scan. - `-O` enables OS detection. ### macOS macOS uses the same commands as Linux since it is a UNIX-like system. #### 1. `netstat` ```sh sudo netstat -tuln ``` #### 2. `ss` This command is not installed by default on macOS, but it can be used after installation via Homebrew: ```sh brew install iproute2mac sudo iproute2mac ss -tuln ``` #### 3. `lsof` ```sh sudo lsof -i -P -n | grep LISTEN ``` #### 4. `nmap` ```sh sudo nmap -sT -O localhost ``` ### Windows #### 1. `netstat` Open the command prompt (cmd) as an administrator and execute: ```sh netstat -ano | findstr LISTEN ``` - `-a` displays all connections and listening ports. - `-n` shows numerical addresses and ports. - `-o` displays the corresponding process identifier (PID). #### 2. `PowerShell` Open PowerShell as an administrator and execute: ```sh Get-NetTCPConnection | Where-Object { $_.State -eq 'Listen' } ``` #### 3. `CurrPorts` This is a graphical tool from NirSoft that allows you to view open ports. Download it from the [official NirSoft website](https://www.nirsoft.net/utils/cports.html) and run it to see the open ports. #### 4. `nmap` Download and install `nmap` from the [official website](https://nmap.org/), then run the following in the command prompt: ```sh nmap -sT -O localhost ``` ### Conclusion To check for open ports on different operating systems, you can use built-in tools such as `netstat`, `ss`, or `lsof`, or external tools like `nmap`. For a more user-friendly graphical interface on Windows, you can utilize the `CurrPorts` application.