Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- Basic Network Scanner
- Example useage:
- PowerShell -ExecutionPolicy Bypass .\scanner.ps1 <Base IP> <Port>
- PowerShell -ExecutionPolicy Bypass .\scanner.ps1 192.168.20 80
- #>
- $ErrorActionPreference= 'silentlycontinue' #ignore errors
- #check for user input
- if($args[0]){
- $baseIP = $args[0]
- }else{
- $baseIP = "192.168.1"
- }
- if($args[1]){
- $port = $args[1]
- }else{
- $port = 80
- }
- $rangeIP = 1..254
- foreach ($range in $rangeIP){
- $ip = "{0}.{1}" -F $baseIP,$range
- 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