@echo off
setlocal EnableExtensions DisableDelayedExpansion
title IP Info - Allow local IP detection in Chrome
set "IPINFO_POLICY_KEY=HKCU\Software\Policies\Google\Chrome\WebRtcLocalIpsAllowedUrls"
set "IPINFO_SITE=https://ipinfo.vutv.in"
echo Allowing Chrome to expose local IP addresses only to %IPINFO_SITE%
echo Applies to the current Windows user. Other allowed sites are preserved.
echo.
for /f "tokens=1,2,*" %%A in ('reg query "%IPINFO_POLICY_KEY%" 2^>nul') do (
    if /I "%%B"=="REG_SZ" if /I "%%C"=="%IPINFO_SITE%" goto done
)
for /L %%N in (1,1,1000) do (
    reg query "%IPINFO_POLICY_KEY%" /v %%N >nul 2>&1
    if errorlevel 1 (
        reg add "%IPINFO_POLICY_KEY%" /v %%N /t REG_SZ /d "%IPINFO_SITE%" /f >nul
        if errorlevel 1 goto failed
        goto done
    )
)
echo No free policy entry found. Ask your administrator to add this site.
goto failed
:done
echo Chrome policy is configured for %IPINFO_SITE%
echo Completely exit Chrome, open it again, return to reqip and click Detect local IP.
echo To verify: open chrome://policy and find WebRtcLocalIpsAllowedUrls.
echo Chrome may display Managed by your organization while this policy is set.
echo Organization policies may take precedence over this user setting.
echo To remove this site's allowance, run the undo file available on reqip.
pause
exit /b 0
:failed
echo The policy could not be configured. Ask your Windows or Chrome administrator.
pause
exit /b 1
