diff --git a/README.md b/README.md index 27eb78cf..eefa2ca7 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ The following PowerShell scripts can be found in the `Scripts/` subfolder: * [poweroff.ps1](Scripts/poweroff.ps1) - halts the local computer, administrator rights might be needed * [news.ps1](Scripts/news.ps1) - prints the latest news * [reboot.ps1](Scripts/reboot.ps1) - reboots the local computer, administrator rights might be needed +* [scan-ports.ps1](Scripts/scan-ports.ps1) - scans the network for open/closed ports * [send-email.ps1](Scripts/send-email.ps1) - sends an email message * [send-udp.ps1](Scripts/send-udp.ps1) - sends a UDP datagram message to the given IP address and port * [SHA1.ps1](Scripts/SHA1.ps1) - prints the SHA1 checksum of the given file diff --git a/Scripts/scan-ports.ps1 b/Scripts/scan-ports.ps1 new file mode 100755 index 00000000..7426c850 --- /dev/null +++ b/Scripts/scan-ports.ps1 @@ -0,0 +1,27 @@ +#!/snap/bin/powershell + +# Syntax: ./scan-ports.ps1 +# Description: scans the network for open/closed ports +# Author: Markus Fleschutz +# Source: github.com/fleschutz/PowerShell +# License: CC0 + +$network = "192.168.178" +$port = 8000 +$range = 1..254 +$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) { + write-host "$ip port $port open" + $socket.Close() + } else { + write-host "$ip port $port not open" + } + } +} +exit 0