chore: snapshot current intranet work
This commit is contained in:
@@ -1,12 +1,32 @@
|
||||
param(
|
||||
[string]$ListenAddress = "0.0.0.0",
|
||||
[int]$Port = 8010,
|
||||
[string]$RuleName = "MyIntranetApp-8010"
|
||||
[string]$RuleName = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
netsh interface portproxy delete v4tov4 listenport=$Port listenaddress=$ListenAddress | Out-Null
|
||||
if ([string]::IsNullOrWhiteSpace($RuleName)) {
|
||||
$RuleName = "MyIntranetApp-$Port"
|
||||
}
|
||||
|
||||
$windowsIps = Get-NetIPAddress -AddressFamily IPv4 |
|
||||
Where-Object {
|
||||
$_.IPAddress -notlike '127.*' `
|
||||
-and $_.IPAddress -notlike '169.254*' `
|
||||
-and $_.InterfaceAlias -notlike '*WSL*'
|
||||
} |
|
||||
Select-Object -ExpandProperty IPAddress
|
||||
|
||||
$listenAddresses = @($ListenAddress)
|
||||
if ($ListenAddress -eq "0.0.0.0") {
|
||||
$listenAddresses += $windowsIps
|
||||
}
|
||||
$listenAddresses = $listenAddresses | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -Unique
|
||||
|
||||
foreach ($address in $listenAddresses) {
|
||||
netsh interface portproxy delete v4tov4 listenport=$Port listenaddress=$address | Out-Null
|
||||
}
|
||||
|
||||
$existingRule = Get-NetFirewallRule -DisplayName $RuleName -ErrorAction SilentlyContinue
|
||||
if ($existingRule) {
|
||||
|
||||
@@ -3,6 +3,8 @@ set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
PORT="${1:-${INTRANET_PORT:-8010}}"
|
||||
|
||||
if [ ! -x ".venv/bin/python" ]; then
|
||||
echo "가상환경이 없습니다. 먼저 아래를 실행하세요."
|
||||
echo "python3 -m venv .venv"
|
||||
@@ -12,5 +14,6 @@ if [ ! -x ".venv/bin/python" ]; then
|
||||
fi
|
||||
|
||||
export INTRANET_AUTO_RELOAD="${INTRANET_AUTO_RELOAD:-1}"
|
||||
export INTRANET_PORT="$PORT"
|
||||
|
||||
exec ./.venv/bin/python main.py
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
@echo off
|
||||
setlocal
|
||||
|
||||
net session >nul 2>&1
|
||||
if not "%errorlevel%"=="0" (
|
||||
echo This script must be run as Administrator.
|
||||
echo.
|
||||
echo 1. Open Windows Start menu.
|
||||
echo 2. Type cmd.
|
||||
echo 3. Right-click Command Prompt and choose "Run as administrator".
|
||||
echo 4. Run this command:
|
||||
echo %~f0 %*
|
||||
echo.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
set SCRIPT_DIR=%~dp0
|
||||
set WSL_IP=%~1
|
||||
|
||||
if "%WSL_IP%"=="" (
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%setup_windows_all_portproxies.ps1"
|
||||
) else (
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%setup_windows_all_portproxies.ps1" -WslIp %WSL_IP%
|
||||
)
|
||||
|
||||
endlocal
|
||||
@@ -0,0 +1,83 @@
|
||||
param(
|
||||
[string]$ListenAddress = "0.0.0.0",
|
||||
[string]$WslIp = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$apps = @(
|
||||
@{ Name = "hm-biz-process"; Port = 8000; RuleName = "HM-BIZ-PROCESS-8000" },
|
||||
@{ Name = "my-intranet-app"; Port = 8010; RuleName = "MyIntranetApp-8010" },
|
||||
@{ Name = "b17301"; Port = 8020; RuleName = "B17301-8020" }
|
||||
)
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($WslIp)) {
|
||||
$detected = wsl.exe hostname -I 2>$null
|
||||
if (-not $detected) {
|
||||
throw "WSL IP를 자동으로 찾지 못했습니다. -WslIp 옵션으로 직접 지정해 주세요."
|
||||
}
|
||||
|
||||
$WslIp = (($detected -split "\s+") | Where-Object { $_ -match '^\d+\.\d+\.\d+\.\d+$' } | Select-Object -First 1)
|
||||
if (-not $WslIp) {
|
||||
throw "WSL IP를 자동으로 파싱하지 못했습니다. -WslIp 옵션으로 직접 지정해 주세요."
|
||||
}
|
||||
}
|
||||
|
||||
$windowsIps = Get-NetIPAddress -AddressFamily IPv4 |
|
||||
Where-Object {
|
||||
$_.IPAddress -notlike '127.*' `
|
||||
-and $_.IPAddress -notlike '169.254*' `
|
||||
-and $_.InterfaceAlias -notlike '*WSL*'
|
||||
} |
|
||||
Select-Object -ExpandProperty IPAddress
|
||||
|
||||
$listenAddresses = @($ListenAddress)
|
||||
if ($ListenAddress -eq "0.0.0.0") {
|
||||
$listenAddresses += $windowsIps
|
||||
}
|
||||
$listenAddresses = $listenAddresses | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -Unique
|
||||
|
||||
Write-Host "Setting Windows portproxy for all WSL apps..." -ForegroundColor Cyan
|
||||
Write-Host "WSL IP: $WslIp"
|
||||
|
||||
foreach ($app in $apps) {
|
||||
$port = [int]$app.Port
|
||||
$ruleName = [string]$app.RuleName
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "$($app.Name): $port" -ForegroundColor Cyan
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
$existingRule = Get-NetFirewallRule -DisplayName $ruleName -ErrorAction SilentlyContinue
|
||||
if ($existingRule) {
|
||||
Remove-NetFirewallRule -DisplayName $ruleName | Out-Null
|
||||
}
|
||||
|
||||
New-NetFirewallRule `
|
||||
-DisplayName $ruleName `
|
||||
-Direction Inbound `
|
||||
-Action Allow `
|
||||
-Protocol TCP `
|
||||
-LocalPort $port | Out-Null
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Completed." -ForegroundColor Green
|
||||
Write-Host "Use these URLs from another PC on the intranet:"
|
||||
if ($windowsIps) {
|
||||
foreach ($ip in $windowsIps) {
|
||||
Write-Host "hm-biz-process : http://$ip`:8000"
|
||||
Write-Host "my-intranet-app: http://$ip`:8010"
|
||||
Write-Host "b17301 : http://$ip`:8020"
|
||||
}
|
||||
} else {
|
||||
Write-Host "hm-biz-process : http://<Windows-IP>:8000"
|
||||
Write-Host "my-intranet-app: http://<Windows-IP>:8010"
|
||||
Write-Host "b17301 : http://<Windows-IP>:8020"
|
||||
}
|
||||
Write-Host ""
|
||||
Write-Host "Tip: if WSL restarts and its IP changes, run this script again."
|
||||
@@ -1,6 +1,20 @@
|
||||
@echo off
|
||||
setlocal
|
||||
|
||||
net session >nul 2>&1
|
||||
if not "%errorlevel%"=="0" (
|
||||
echo This script must be run as Administrator.
|
||||
echo.
|
||||
echo 1. Open Windows Start menu.
|
||||
echo 2. Type cmd.
|
||||
echo 3. Right-click Command Prompt and choose "Run as administrator".
|
||||
echo 4. Run this command:
|
||||
echo %~f0 %*
|
||||
echo.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
set SCRIPT_DIR=%~dp0
|
||||
set WSL_IP=%~1
|
||||
set PORT=%~2
|
||||
|
||||
@@ -2,11 +2,15 @@ param(
|
||||
[string]$ListenAddress = "0.0.0.0",
|
||||
[int]$Port = 8010,
|
||||
[string]$WslIp = "",
|
||||
[string]$RuleName = "MyIntranetApp-8010"
|
||||
[string]$RuleName = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($RuleName)) {
|
||||
$RuleName = "MyIntranetApp-$Port"
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($WslIp)) {
|
||||
$detected = wsl.exe hostname -I 2>$null
|
||||
if (-not $detected) {
|
||||
@@ -24,8 +28,24 @@ Write-Host "ListenAddress: $ListenAddress"
|
||||
Write-Host "Port: $Port"
|
||||
Write-Host "WSL IP: $WslIp"
|
||||
|
||||
netsh interface portproxy delete v4tov4 listenport=$Port listenaddress=$ListenAddress | Out-Null
|
||||
netsh interface portproxy add v4tov4 listenport=$Port listenaddress=$ListenAddress connectport=$Port connectaddress=$WslIp
|
||||
$windowsIps = Get-NetIPAddress -AddressFamily IPv4 |
|
||||
Where-Object {
|
||||
$_.IPAddress -notlike '127.*' `
|
||||
-and $_.IPAddress -notlike '169.254*' `
|
||||
-and $_.InterfaceAlias -notlike '*WSL*'
|
||||
} |
|
||||
Select-Object -ExpandProperty IPAddress
|
||||
|
||||
$listenAddresses = @($ListenAddress)
|
||||
if ($ListenAddress -eq "0.0.0.0") {
|
||||
$listenAddresses += $windowsIps
|
||||
}
|
||||
$listenAddresses = $listenAddresses | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -Unique
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
$existingRule = Get-NetFirewallRule -DisplayName $RuleName -ErrorAction SilentlyContinue
|
||||
if ($existingRule) {
|
||||
@@ -39,16 +59,15 @@ New-NetFirewallRule `
|
||||
-Protocol TCP `
|
||||
-LocalPort $Port | Out-Null
|
||||
|
||||
$windowsIps = Get-NetIPAddress -AddressFamily IPv4 |
|
||||
Where-Object { $_.IPAddress -notlike '127.*' -and $_.IPAddress -notlike '169.254*' -and $_.IPAddress -notlike '172.*' } |
|
||||
Select-Object -ExpandProperty IPAddress
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Completed." -ForegroundColor Green
|
||||
Write-Host "Now open this from another PC on the intranet:"
|
||||
Write-Host "http://<Windows-IP>:$Port"
|
||||
if ($windowsIps) {
|
||||
Write-Host "Windows IPv4 candidates: $($windowsIps -join ', ')"
|
||||
foreach ($ip in $windowsIps) {
|
||||
Write-Host "http://$ip`:$Port"
|
||||
}
|
||||
} else {
|
||||
Write-Host "http://<Windows-IP>:$Port"
|
||||
}
|
||||
Write-Host ""
|
||||
Write-Host "Tip: if WSL restarts and its IP changes, run this script again. If you omit -WslIp, the script will detect it automatically."
|
||||
|
||||
@@ -4,7 +4,7 @@ set -euo pipefail
|
||||
WSL_IP="$(hostname -I | awk '{print $1}')"
|
||||
WSL_HOST_IP="$(awk '/nameserver/ {print $2; exit}' /etc/resolv.conf)"
|
||||
WINDOWS_IPS="$(
|
||||
powershell.exe -NoProfile -Command "(Get-NetIPAddress -AddressFamily IPv4 | Where-Object { \$_.IPAddress -notlike '127.*' -and \$_.IPAddress -notlike '169.254*' } | Select-Object -ExpandProperty IPAddress) -join ','" \
|
||||
powershell.exe -NoProfile -Command "(Get-NetIPAddress -AddressFamily IPv4 | Where-Object { \$_.IPAddress -notlike '127.*' -and \$_.IPAddress -notlike '169.254*' -and \$_.InterfaceAlias -notlike '*WSL*' } | Select-Object -ExpandProperty IPAddress) -join ','" \
|
||||
2>/dev/null | tr -d '\r'
|
||||
)"
|
||||
|
||||
@@ -13,7 +13,10 @@ WSL 앱 정보
|
||||
- WSL 내부 IP: ${WSL_IP}
|
||||
- Windows 호스트와 연결된 주소 추정값: ${WSL_HOST_IP}
|
||||
- Windows IPv4 후보: ${WINDOWS_IPS:-확인 실패}
|
||||
- 앱 포트: 8010
|
||||
- 포트 배치:
|
||||
- hm-biz-process: 8000
|
||||
- my-intranet-app: 8010
|
||||
- b17301: 8020
|
||||
|
||||
중요
|
||||
- WSL2에서는 다른 PC가 WSL 내부 IP(${WSL_IP})로 직접 접속하지 못하는 경우가 많습니다.
|
||||
@@ -21,7 +24,7 @@ WSL 앱 정보
|
||||
- 따라서 Windows 관리자 PowerShell에서 portproxy + 방화벽 규칙을 설정해야 합니다.
|
||||
|
||||
다음 단계
|
||||
1. WSL에서 서버 실행: ./scripts/run_server.sh
|
||||
2. Windows 관리자 PowerShell 또는 CMD에서 scripts/setup_windows_portproxy 실행
|
||||
1. WSL에서 my-intranet-app 실행: ./scripts/run_server.sh 8010
|
||||
2. Windows 관리자 PowerShell 또는 CMD에서 scripts/setup_windows_all_portproxies 실행
|
||||
3. 다른 PC 브라우저에서 http://Windows호스트IP:8010 접속
|
||||
EOF
|
||||
|
||||
Reference in New Issue
Block a user