Update intranet tools and voucher comparison
This commit is contained in:
@@ -81,6 +81,31 @@ function Get-WslListeningPorts {
|
||||
return $portMap.Values | Sort-Object Port
|
||||
}
|
||||
|
||||
function Get-DockerPublishedPorts {
|
||||
$publishedPorts = New-Object System.Collections.Generic.HashSet[int]
|
||||
try {
|
||||
$raw = docker ps --format "{{.Ports}}" 2>$null
|
||||
if (-not $raw) {
|
||||
return $publishedPorts
|
||||
}
|
||||
|
||||
foreach ($line in ($raw -split "`r?`n")) {
|
||||
if ([string]::IsNullOrWhiteSpace($line)) {
|
||||
continue
|
||||
}
|
||||
foreach ($match in [regex]::Matches($line, "(?:0\.0\.0\.0|\[::\]):(?<port>\d+)->")) {
|
||||
$port = 0
|
||||
if ([int]::TryParse($match.Groups["port"].Value, [ref]$port)) {
|
||||
[void]$publishedPorts.Add($port)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
return $publishedPorts
|
||||
}
|
||||
return $publishedPorts
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($WslIp)) {
|
||||
$detected = wsl.exe hostname -I 2>$null
|
||||
if (-not $detected) {
|
||||
@@ -110,6 +135,10 @@ $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)
|
||||
$dockerPublishedPorts = @(Get-DockerPublishedPorts)
|
||||
if ($dockerPublishedPorts.Count -gt 0) {
|
||||
Write-Host "Docker-published Windows ports: $((@($dockerPublishedPorts) | Sort-Object) -join ', ')" -ForegroundColor Cyan
|
||||
}
|
||||
|
||||
$knownPortEntries = @()
|
||||
foreach ($knownPort in ($knownPorts.Keys | Sort-Object)) {
|
||||
@@ -162,7 +191,13 @@ foreach ($entry in $reachableEntries) {
|
||||
|
||||
foreach ($address in $listenAddresses) {
|
||||
netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$address | Out-Null
|
||||
netsh interface portproxy add v4tov4 listenport=$port listenaddress=$address connectport=$port connectaddress=$WslIp
|
||||
if ($dockerPublishedPorts -notcontains $port) {
|
||||
netsh interface portproxy add v4tov4 listenport=$port listenaddress=$address connectport=$port connectaddress=$WslIp
|
||||
}
|
||||
}
|
||||
|
||||
if ($dockerPublishedPorts -contains $port) {
|
||||
Write-Host " Docker already publishes this port on Windows; stale portproxy entries were removed and only firewall is refreshed." -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
$existingRule = Get-NetFirewallRule -DisplayName $ruleName -ErrorAction SilentlyContinue
|
||||
|
||||
Reference in New Issue
Block a user