mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-01-23 06:08:36 +01:00
Added scan-ports.ps1
This commit is contained in:
parent
f548434d31
commit
011722cd1d
@ -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
|
* [poweroff.ps1](Scripts/poweroff.ps1) - halts the local computer, administrator rights might be needed
|
||||||
* [news.ps1](Scripts/news.ps1) - prints the latest news
|
* [news.ps1](Scripts/news.ps1) - prints the latest news
|
||||||
* [reboot.ps1](Scripts/reboot.ps1) - reboots the local computer, administrator rights might be needed
|
* [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-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
|
* [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
|
* [SHA1.ps1](Scripts/SHA1.ps1) - prints the SHA1 checksum of the given file
|
||||||
|
27
Scripts/scan-ports.ps1
Executable file
27
Scripts/scan-ports.ps1
Executable file
@ -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
|
Loading…
Reference in New Issue
Block a user