Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- Basic Port Scanner
- Example useage:
- PowerShell -ExecutionPolicy Bypass .\scanner.ps1 <IP> <Start Port> <End Port>
- PowerShell -ExecutionPolicy Bypass .\scanner.ps1 192.168.1.1 20 30
- #>
- $ErrorActionPreference= 'silentlycontinue' #ignore errors
- #check for user input
- if($args[0]){
- $ip = $args[0]
- }else{
- write-host "IP Address needed!!!"
- exit
- }
- if($args[2]){
- $ports = $args[1]..$args[2]
- }else{
- write-host "port range needed!!!"
- exit
- }
- foreach ($port in $ports){
- write-host "Scanning $ip port $port..." -NoNewline
- if(Test-Connection -BufferSize 32 -Count 1 -Quiet -ComputerName $ip){
- $socket = new-object System.Net.Sockets.TcpClient($ip, $port)
- If($socket.Connected){
- $socket.Close()
- write-host "`r$ip port $port is open." -foregroundcolor "red" #if port open output
- }
- }
- write-host "`r" -NoNewline #clear line is port not open
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement