Port-Test Skript: Unterschied zwischen den Versionen
Aus Wiki-WebPerfect
Admin (Diskussion | Beiträge) |
Admin (Diskussion | Beiträge) |
||
Zeile 1: | Zeile 1: | ||
[[Datei:Port-test skript.PNG|right]] | [[Datei:Port-test skript.PNG|right]] | ||
− | + | <source lang="powershell"> | |
Param($customserver, $customports) | Param($customserver, $customports) | ||
Zeile 55: | Zeile 55: | ||
[array]$server = @() | [array]$server = @() | ||
− | + | #-------------------------------------------------- | |
+ | # Beispiel-Server und Ports | ||
+ | # Replace the Servers | ||
# Google Web-Server | # Google Web-Server | ||
$ports = "80,443,9443" | $ports = "80,443,9443" | ||
Zeile 66: | Zeile 68: | ||
"dc01.lab" | "dc01.lab" | ||
test-start $server $ports | test-start $server $ports | ||
+ | #-------------------------------------------------- | ||
} | } | ||
return | return | ||
Zeile 71: | Zeile 74: | ||
cls | cls | ||
Main $customserver $customports | Main $customserver $customports | ||
+ | </source> |
Version vom 27. Juni 2017, 14:30 Uhr
Param($customserver, $customports) Function Connection-test($server,$singleport) { Return (Test-netConnection $server -port $singleport -WarningAction SilentlyContinue -ErrorAction SilentlyContinue ).TcpTestSucceeded } Function Server-test($server,$ports) { if([bool]($server -as [ipaddress]) -ne $true) { $serverip=$null $serverip = (Test-Connection $server -Count 1 -WarningAction SilentlyContinue -ErrorAction SilentlyContinue).IPV4Address.ipaddresstostring } else {[string]$serverip = $server} if($serverip) { ('{0,-55} {1,-20}' -f "`t$env:COMPUTERNAME -> $server", "$serverip") | write-host -NoNewline -fore DarkGray "TCP" | Write-host -NoNewLine -Fore Green foreach($singleport in ($ports.trim()).split(",")) { $status = connection-test $server $singleport if($status){ Write-host ",$status`:$singleport" -NoNewline -fore Green } else { Write-host ",$status`:$singleport" -NoNewline -fore Red } } } else { write-host ('{0,-55}' -f "`t$env:COMPUTERNAME -> $server") -NoNewline -fore DarkGray Write-host " DNS FAILED" -NoNewline -fore Red Write-host "`r" return } Write-host "`r" } Function test-start($servers, $ports) { foreach($server in $servers) { if(!$server){break} Server-test $server $ports } } Function Main($customserver, $customports) { if(($customserver) -and ($customports)) { Write-host "Starting custom port test" -ForegroundColor Yellow test-start $customserver $customports } Else { #Write-host "Starting default port test" -ForegroundColor Yellow [array]$ports = @() [array]$server = @() #-------------------------------------------------- # Beispiel-Server und Ports # Replace the Servers # Google Web-Server $ports = "80,443,9443" $server = "google.ch" test-start $server $ports # Windows AD servers $ports = "53,88,135,389,445,464,636,3268,3269" $server = "dc02.lab", "dc01.lab" test-start $server $ports #-------------------------------------------------- } return } cls Main $customserver $customports