Dieses Powershell-Script prüft in einer Endlosschleife, ob der Port am Zielsystem offen ist. Ideal für Tests von Firewall- und Anwendungskonfigurationen.
Das Script kann einfach als .ps1-Datei abgespeichert und ausgeführt werden. Beim Start des Scripts, wird das Zielsystem und der Port in einer Endlosschleife abgefragt. Die Ausgabe umfasst Uhrzeit und Portstatus:
$target = Read-Host 'Ziel'; $port = Read-Host 'Port'; For ($i=1; $i -gt 0; $i++) { $test = New-Object System.Net.Sockets.TcpClient; $time = Get-Date -UFormat %T; try { $test.Connect($target, $port); $test.Close(); Write-Host $time "OK"; Start-Sleep -s 2; } catch { $test.Close(); Write-Host $time "ERROR"; Start-Sleep -s 2; } }