Powershell – PortScanner

PortScanner

 

 

 

 

 

 

lets create a Port Scanner tool, which will test each port listenning on the destination i.p

usually the most  common ports we are checking are on the list below –

http – 80

ftp – 21

ssl – 443

telnet -23

ssh – 22

so ..there are few ways to tell the function to go over each port and test it ,i chose to do it with Hashtable

of-course you can use also with an array –

Hashtable example –

$Ports = @{
http=80
ftp=21
ssl=443
telnet =23
ssh = 22
}

O.k Not that we created a table we should loop through it with a command .

so the command needs to test if the Socket on the listening side is open we’ll use it with –

New-Object System.Net.Sockets.TcpClient

and add it to a variable called $Socket = New-Object System.Net.Sockets.TcpClient

one of the member of this object is ‘Connect‘ which also required with I.P Address and Port ,like –

$Socket.Connect(“192.168.10.252” ,443)

so now we know what required we’ll wrap it in to a function call the I.P we’ll choose and test it with each Port we

added before to the Hashtable we created on the beginning .

 

 

you might interest also with post Powershell Test-Socket.

 

(Visited 226 times, 1 visits today)

Leave a Reply