Port Scan

Linux

Netcat
echo "" | nc -v -n -z -r -w1 [ip_address] [port/port_range]

Tip

Netcat will iterate through ports in reverse order when a port range is specified. Use the randomize (-r) option to avoid this behavior and iterate through ports randomly.

Windows

PowerShell
1..1024 | % {echo ((New-Object Net.Sockets.TcpClient).Connect("[ip_address]",$_)) "Port $_ is open" } 2> $null
PowerShell Module
Import-Module Test-TcpPort.psm1
1..1024 | % { Test-TcpPort -Hostname "[hostname]" -Port $_ }

Source**: Test-TcpPort.psm1**

Netcat
for /L %i in ([first_port],1,[last_port]) do @echo "" | nc -n -vv -w3 [ip_address] %i 1>nul 2>nul && @echo [*] port %i is open
for /F %i in (ports.txt) do @echo "" | nc -n -vv -w3 [ip_address] %i 1>nul 2>nul && @echo [*] port %i is open