Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Get WSL2 IP
- $wslIp = wsl.exe -e "ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -d '/' -f 1"
- # List of containers and their ports to forward
- $containerPorts = @(
- @{ ContainerName = "meshcentral"; Ports = @(3000, 3001, 3002) },
- @{ ContainerName = "plex"; Ports = @(32400, 3005, 8324, 32469) },
- @{ ContainerName = "sonarr"; Ports = @(8989) },
- @{ ContainerName = "radarr"; Ports = @(7878) },
- @{ ContainerName = "prowlarr"; Ports = @(9696) },
- @{ ContainerName = "debridav"; Ports = @(8081) },
- @{ ContainerName = "jellyfin"; Ports = @(8096) },
- @{ ContainerName = "overseerr"; Ports = @(5055) },
- @{ ContainerName = "tautulli"; Ports = @(8181) },
- @{ ContainerName = "seerrbridge"; Ports = @(8082) },
- @{ ContainerName = "traefik"; Ports = @(80, 443, 8080) }
- )
- # Function to forward a single port
- function Forward-Port {
- param (
- [string]$containerName,
- [int]$port,
- [string]$wslIp
- )
- # Remove existing rule
- try {
- netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=$port -ErrorAction Stop
- Write-Host "Removed existing port proxy for $containerName:$port"
- } catch {
- Write-Host "No existing port proxy found for $containerName:$port. Continuing"
- }
- # Add new rule with updated IP
- try {
- netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=$port connectaddress=$wslIp connectport=$port -ErrorAction Stop
- Write-Host "Port $port forwarded for $containerName"
- } catch {
- Write-Error "Failed to forward port $port for $containerName: $_"
- }
- }
- # Forward ports for each container
- foreach ($container in $containerPorts) {
- foreach ($port in $container.Ports) {
- Forward-Port -containerName $container.ContainerName -port $port -wslIp $wslIp
- }
- }
- Write-Host "Port forwarding completed."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement