feat: funciones PowerShell infra — firewall y portproxy

Funciones PowerShell para gestión de red en Windows: win_firewall_add_rule,
win_firewall_remove_rule, win_portproxy_add y win_portproxy_remove.
Útiles para configurar acceso de red en entornos WSL2.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-30 14:24:45 +02:00
parent 3c250a9252
commit 2fbf4ef62e
8 changed files with 426 additions and 0 deletions
@@ -0,0 +1,61 @@
---
name: win_portproxy_remove
kind: function
lang: ps
domain: infra
version: "1.0.0"
purity: impure
signature: "win_portproxy_remove -ListenPort <int> [-ListenAddr <string>]"
description: "Elimina una regla de port proxy v4tov4 de netsh identificada por ListenAddr:ListenPort. Si la regla no existe, termina con éxito sin hacer nada (idempotente). Requiere privilegios de Administrador."
tags: [portproxy, netsh, windows, network, infra, wsl2, cleanup, proxy]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: "error_go_core"
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "powershell/functions/infra/win_portproxy_remove.ps1"
---
## Uso
```powershell
# Eliminar portproxy en puerto 9222 (listenaddr por defecto: 0.0.0.0)
.\win_portproxy_remove.ps1 -ListenPort 9222
# Con listenaddr explícito
.\win_portproxy_remove.ps1 -ListenAddr 0.0.0.0 -ListenPort 9222
```
```bash
# Desde WSL2
powershell.exe -ExecutionPolicy Bypass -File win_portproxy_remove.ps1 -ListenPort 9222
```
## Parametros
| Parametro | Tipo | Obligatorio | Default | Descripcion |
|---------------|--------|-------------|-------------|------------------------------------------------------|
| `-ListenPort` | int | si | — | Puerto de escucha de la regla a eliminar (1-65535) |
| `-ListenAddr` | string | no | `0.0.0.0` | Dirección IP de escucha de la regla a eliminar |
## Notas
- Requiere ejecutarse como **Administrador** en Windows.
- Idempotente: si la regla no existe, sale con exit code 0 y mensaje informativo.
- Complementa `win_portproxy_add` para teardown limpio.
- La regla se identifica por la combinación `listenaddress:listenport` — debe coincidir exactamente con la usada en `win_portproxy_add`.
- Retorna exit code 0 si tuvo éxito (o la regla no existía), 1 si hubo error.
## Teardown completo WSL2 → Chrome CDP
```bash
# 1. Eliminar portproxy
powershell.exe -ExecutionPolicy Bypass -File win_portproxy_remove.ps1 -ListenPort 9222
# 2. Eliminar regla de firewall
powershell.exe -ExecutionPolicy Bypass -File win_firewall_remove_rule.ps1 -Name "CDP-9222"
```