Sitemap
Nalla Muthu

Nalla Muthu

PowerShell — Port Scan

1 min readMar 21, 2020

In a corporate environment, where NMAP and other port scanning tools are restricted. Adversary can make use of windows inbuilt Powershell to perform port scan if it is not restricted by the GPO (Group Policy)

Introduction — PowerShell (Microsoft):

Windows PowerShell is a Windows command-line shell designed especially for system administrators. Windows PowerShell includes an interactive prompt and a scripting environment that can be used independently or in combination.

Check Port or Single IP:

Test-NetConnection -Port 80 192.168.1.1

Check Port Range in single IP

Get Nalla Muthu’s stories in your inbox

Join Medium for free to get updates from this writer.

1..1024 | % {echo ((new-object Net.Sockets.TcpClient).Connect(“192.168.1.1”,$_)) “Port $_ is open!”} 2>$null

Check Port List in Single IP

80,443,8080 | % {echo ((new-object Net.Sockets.TcpClient).Connect(“192.168.1.1”,$_)) “Port $_ is open!”} 2>$null

Check Port List in IP List

“192.168.1.1”,”10.1.1.2" | % { $a = $_; write-host “ — — — “; write-host “$a”; 80,443,445,8080 | % {echo ((new-object Net.Sockets.TcpClient).Connect(“$a”,$_)) “Port $_ is open!”} 2>$null}

Check Port List in IP List from File

Get-Content .\ip.txt | % { $a = $_; write-host “ — — — “; write-host “$a”; 80,443,445,8080 | % {echo ((new-object Net.Sockets.TcpClient).Connect(“$a”,$_)) “Port $_ is open!”} 2>$null}

--

--