# TCP 探测 Redis,不打印口令 $ErrorActionPreference = 'Continue' function Test-Port($h, $p) { try { $tcp = New-Object System.Net.Sockets.TcpClient $iar = $tcp.BeginConnect($h, [int]$p, $null, $null) $ok = $iar.AsyncWaitHandle.WaitOne(3000, $false) if (-not $ok) { $tcp.Close(); return "TIMEOUT $h`:$p" } $tcp.EndConnect($iar) $tcp.Close() return "OPEN $h`:$p" } catch { return "FAIL $h`:$p $($_.Exception.Message)" } } Write-Output (Test-Port '127.0.0.1' 6379) Write-Output (Test-Port '10.206.0.14' 6379) Write-Output (Test-Port '10.206.0.15' 6379) Write-Output (Test-Port '10.206.0.14' 3306) # 从 REDIS_URL 解析 host $raw = (Get-Content 'E:\wwwroot\.env' | Where-Object { $_ -match '^REDIS_URL=' } | Select-Object -First 1) if ($raw) { if ($raw -match '@([^:/]+):(\d+)/(\d+)') { Write-Output ("url_host=" + $Matches[1] + " port=" + $Matches[2] + " db=" + $Matches[3]) Write-Output (Test-Port $Matches[1] $Matches[2]) } } Write-Output 'TCP_DONE'