Еще несколько экспериментов сделали то, что мне было нужно, хотя и грубо, но это работает, потому что возвращается только адрес в первой строке.
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| find "IPv4 Address"') do echo %%a >> C:\Windows\Temp\ip.txt
set /p ip= < C:\Windows\Temp\ip.txt
Для тех, кто заинтересован в эффективном переключении настроек прокси в win7, представлен полный скрипт. Для вашей настройки потребуется ручное редактирование имени, прокси-сервера, шлюзов по умолчанию и записей адресов DNS.
@ECHO OFF
REM Elevation changer script, uac prompt called to confirm.
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
:--------------------------------------
REM Find current state of proxy settings and assign output to variable to make decision: dis- or enable?
REG QUERY "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable > C:\Windows\Temp\proxyinfo.txt
FOR /f "tokens=3 delims= " %%a IN (C:\Windows\Temp\proxyinfo.txt) DO ECHO %%a > C:\Windows\Temp\proxyval.txt
set /p var= <C:\Windows\Temp\proxyval.txt
REM Find current ip address and assign output to variable to re-insert in config commands
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| find "IPv4 Address"') do echo %%a >> C:\Windows\Temp\ip.txt
set /p ip= < C:\Windows\Temp\ip.txt
REM Decide action to follow
IF %var% == 0x0 ECHO Proxy is currently disabled.
IF %var% == 0x1 ECHO Proxy is currently enabled.
REM Bailout option
ECHO Switch the proxy state? This will also adjust dns and default gateway settings.
choice /c yn
if errorlevel 2 GOTO BAIL
if errorlevel 1 GOTO DOIT
:BAIL
ECHO Nothing has changed, run this script again when you made up your mind.
ECHO Press any key to close this window.
GOTO CLEAN
:DOIT
IF %var% == 0x0 GOTO ISDISABLED
IF %var% == 0x1 GOTO ISENABLED
:ISDISABLED
REM Enable all required settings to activate proxy in registry (enable, address, override for local)
ECHO Changing settings to enable proxy now...
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^
/v ProxyEnable /t REG_DWORD /d 1 /f > nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^
/v ProxyServer /t REG_SZ /d 172.16.255.1:8080 /f > nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^
/v ProxyOverride /t REG_SZ /d ^<local^> /f > nul
REM Change dns settings
netsh interface ip set dns "Local Area Connection" static 172.16.100.100 primary n
netsh interface ip add dns "Local Area Connection" 172.16.100.101 index=2 n
REM Change default gateway
netsh interface ip set address "Local Area Connection" static address=%ip% mask=255.255.0.0 gateway=10.100.255.254
ECHO Proxy is now enabled, run this script again to disable.
ECHO Press any key to close this window.
GOTO CLEAN
:ISENABLED
REM Disable proxy
ECHO Changing settings to disable proxy now...
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^
/v ProxyEnable /t REG_DWORD /d 0 /f > nul
REM Change dns settings
netsh interface ip set dns "Local Area Connection" static 8.8.8.8 primary n
netsh interface ip add dns "Local Area Connection" 8.8.4.4 index=2 n
REM Change default gateway
netsh interface ip set address "Local Area Connection" static address=%ip% mask=255.255.0.0 gateway=10.100.255.250
ECHO Proxy is now disabled, run this script again to enable.
ECHO Press any key to close this window.
GOTO CLEAN
:CLEAN
del C:\Windows\Temp\proxy*.txt
del C:\Windows\Temp\ip*.txt
GOTO END
:END
PAUSE > nul