Created
January 17, 2022 19:49
-
-
Save kuan51/b33266497fd016c412ae03fece314d71 to your computer and use it in GitHub Desktop.
Powershell Port Scanner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$port = 22 | |
$net = “192.168.1” | |
$range = 1..254 | |
foreach ($r in $range) | |
{ | |
$ip = “{0}.{1}” -F $net,$r | |
if(Test-Connection -BufferSize 32 -Count 1 -Quiet -ComputerName $ip) | |
{ | |
$socket = new-object System.Net.Sockets.TcpClient($ip, $port) | |
If($socket.Connected) | |
{ | |
"$ip listening to port $port" | |
$socket.Close() } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment