Answer the question
In order to leave comments, you need to log in
Script for changing network settings, why doesn't it work "on the fly"?
Initially, the script was taken from somewhere on the net, modified a little for myself (sorry for the crooked English):
@ECHO OFF
:: Variables (set IFACE name as in your adapter settings name)
SET IFACE="Ethernet"
SET IP=192.168.0.10
SET IPD=DHCP
SET MASK=255.255.255.0
SET GATEWAY=192.168.0.1
SET GWMETRIC=1
SET DNS1=8.8.8.8
SET DNS2=77.88.8.8
:: Script
SET /P settings="Choose option (1 - STATIC, 2 - DHCP): "
ECHO Current option - %settings%
IF %settings% EQU 1 (GOTO STATIC) ELSE (IF %settings% EQU 2 (GOTO DHCP) ELSE (GOTO WRONG))
:WRONG
ECHO WRONG OPTION!
GOTO QUIT
:STATIC
ECHO Current choosen network settings:
ECHO IP-address: %IP%
ECHO Network mask: %MASK%
ECHO Gateway: %GATEWAY%
netsh interface ip set address %IFACE% static %IP% %MASK% %GATEWAY% %GWMETRIC%
ECHO Primary DNS server: %DNS1%
netsh interface ip set dns %IFACE% static %DNS1% validate=no
ECHO Secondary DNS server: %DNS2%
netsh interface ip add dns %IFACE% %DNS2% index=2 validate=no
GOTO IPSHOWQ
:DHCP
ECHO Current choosen network settings: === %IPD% ===
netsh interface ip set address %IFACE% %IPD%
netsh interface ip set dns %IFACE% %IPD%
GOTO IPSHOWQ
:IPSHOWQ
SET /P IPINFO="Show network configuration? (y - YES, n - NO): "
IF %IPINFO% NEQ y GOTO QUIT
:IPSHOW
::ipconfig /all
netsh interface ip show addresses name=%IFACE%
netsh interface ip show dns name=%IFACE%
:QUIT
ECHO Bye-bye!
pause
netsh interface ip show addresses name=%IFACE%
netsh interface ip show dns name=%IFACE%
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question