Jrdgamer11
Here is a literal copy and paste from my machine where I just tested this:
$port = (80)
$network = “192.168.42”
$range = 240..252
$ErrorActionPreference= ‘silentlycontinue’
$(Foreach ($add in $range)
{ $ip = “{0}.{1}” –F $network,$add
Write-Progress “Scanning Network” $ip -PercentComplete (($add/$range.Count)*100)
If(Test-Connection –BufferSize 32 –Count 1 –quiet –ComputerName $ip)
{ $socket = new-object System.Net.Sockets.TcpClient($ip, $port)
If($socket.Connected) { “$ip port $port open”
$socket.Close() }
else { “$ip port $port not open ” }
}
}) | Out-File D:\Documents\Scripts\PowerShell\PortScan\PortScan.csv
With results:
192.168.42.240 port 80 open
192.168.42.241 port 80 open
192.168.42.247 port 80 open
192.168.42.248 port 80 open
192.168.42.249 port 80 open
192.168.42.250 port 80 open
As was noted above, make sure the CSV location can be written to, my line 14 is where I have "My Documents" redirected to on my laptop and then some sub folders.
The folders all need to exist ahead of time. The CSV itself does not.
And this should work on WiFi as well as Wired, but if you are connected to nothing then what are you scanning?
-Casper042