Refactor data loading and query projections
This commit is contained in:
@@ -14,7 +14,7 @@ $knownPorts = @{
|
||||
function Get-WslListeningPorts {
|
||||
$raw = wsl.exe bash -lc "ss -ltnH 2>/dev/null"
|
||||
if (-not $raw) {
|
||||
throw "WSL listening TCP 포트를 확인하지 못했습니다."
|
||||
return @()
|
||||
}
|
||||
|
||||
$portMap = @{}
|
||||
@@ -110,8 +110,27 @@ $listenAddresses = $listenAddresses | Where-Object { -not [string]::IsNullOrWhit
|
||||
Write-Host "Setting Windows portproxy for all active WSL TCP ports..." -ForegroundColor Cyan
|
||||
Write-Host "WSL IP: $WslIp"
|
||||
$portEntries = @(Get-WslListeningPorts)
|
||||
|
||||
$knownPortEntries = @()
|
||||
foreach ($knownPort in ($knownPorts.Keys | Sort-Object)) {
|
||||
$existingEntry = @($portEntries | Where-Object { [int]$_.Port -eq [int]$knownPort } | Select-Object -First 1)
|
||||
if ($existingEntry -and $existingEntry.Count -gt 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
$hosts = New-Object System.Collections.Generic.List[string]
|
||||
$hosts.Add("not-listening-yet")
|
||||
$knownPortEntries += [ordered]@{
|
||||
Port = [int]$knownPort
|
||||
Hosts = $hosts
|
||||
ExternallyReachable = $true
|
||||
Assumed = $true
|
||||
}
|
||||
}
|
||||
|
||||
$portEntries = @($portEntries + $knownPortEntries | Sort-Object Port)
|
||||
if (-not $portEntries -or $portEntries.Count -eq 0) {
|
||||
throw "외부에서 접근 가능한 WSL TCP 포트를 찾지 못했습니다."
|
||||
throw "등록할 WSL TCP 포트를 찾지 못했습니다."
|
||||
}
|
||||
|
||||
Write-Host "Detected ports: $((@($portEntries | ForEach-Object { $_.Port })) -join ', ')"
|
||||
@@ -130,9 +149,16 @@ foreach ($entry in $reachableEntries) {
|
||||
$appInfo = $knownPorts[$port]
|
||||
$displayName = if ($appInfo) { [string]$appInfo.Name } else { "wsl-port-$port" }
|
||||
$ruleName = if ($appInfo) { [string]$appInfo.RuleName } else { "WSL-PORT-$port" }
|
||||
$assumed = $false
|
||||
if ($entry.Contains("Assumed")) {
|
||||
$assumed = [bool]$entry.Assumed
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "$displayName : $port ($($entry.Hosts -join ', '))" -ForegroundColor Cyan
|
||||
if ($assumed) {
|
||||
Write-Host " Known service port is not listening yet; portproxy will still be refreshed to the current WSL IP." -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
foreach ($address in $listenAddresses) {
|
||||
netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$address | Out-Null
|
||||
|
||||
Reference in New Issue
Block a user