#powershell #networking #netstat #ss
Commands to get a list of ports that are currently in use.
Windows
Using PowerShell
$usedPorts = (Get-NetTCPConnection | Select-Object -ExpandProperty LocalPort) +
(Get-NetUDPEndpoint | Select-Object -ExpandProperty LocalPort)Linux
ss
ss -lntup-
-lto get listening ports -
-nto get port number without resolving service name -
-tto include TCP -
-uto include UDP -
-pto include the program name
netstat
Deprecated
This approach is deprecated in favour of using ss
netstat -lntup-
-lto get listening ports -
-nto get port number without resolving service name -
-tto include TCP -
-uto include UDP -
-pto include the program name