中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-06 13:03
48,039 topics / 350,124 posts / today 0 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » Batch Command for Automatically Modifying IP, Gateway, and DNS [Original]
Printable Version  1,519 / 2
Floor1 zhqw Posted 2007-11-06 11:23
新手上路 Posts 6 Credits 18
Save the following content as IP.BAT or IP.CMD

@echo off

rem Change the IP address and gateway to commonly used values

set IP=192.168.3.148
set mask=255.255.255.0
set gateway=192.168.3.254
set DNS1=202.96.64.68
set DNS2=202.96.75.68
set Interface=Local Area Connection

cls
echo.
echo The current network connection properties are as follows:
ipconfig /all
echo.
pause

rem ============== Manual selection setup starts ==============
:MANUAL
cls
echo.
echo.
echo Please select the number of the network connection, press Enter to default to "1. Local Area Connection"
echo.
echo 1. Local Area Connection
echo 2. Local Area Connection 2
echo 3. Local Area Connection 3
echo 4. Local Area Connection 4
echo 5. Local Area Connection 5
echo.
set KEY=1
set /p KEY=Interface:
if %KEY% == 1 set Interface=Local Area Connection
if %KEY% == 2 set Interface=Local Area Connection 2
if %KEY% == 3 set Interface=Local Area Connection 3
if %KEY% == 4 set Interface=Local Area Connection 4
if %KEY% == 5 set Interface=Local Area Connection 5

echo.
echo The default IP address is %IP%, please enter the new IP address and press Enter to set it to the default value
echo.
set /p IP=IP:
echo.
echo The default subnet mask address is %mask%, please enter the new Mask and press Enter to set it to the default value
echo.
set /p mask=Mask:
echo.
echo The default gateway address is %gateway%, please enter the new Gateway and press Enter to set it to the default value
echo.
set /p gateway=Gateway:
ECHO.
echo The default primary DNS address is %DNS1%, please enter the new primary DNS and press Enter to set it to the default value
echo.
set /p DNS1=DNS1:
echo.
echo The default secondary DNS address is %DNS2%, please enter the new secondary DNS and press Enter to set it to the default value
echo.
set /p DNS2=DNS2:

cls
echo.
echo You have set the following for "%Interface%":
echo.
ECHO IP address: %IP%
ECHO Mask: %mask%
ECHO Gateway address: %gateway%
ECHO Primary DNS address: %DNS1%
ECHO Secondary DNS address: %DNS2%
echo.
echo.
set KEY=EXIT
echo Press "1" to enable the above settings, press "2" to reset, press any key to exit
echo.
set /p KEY=Choice:
if %KEY% == 1 goto DO
if %KEY% == 2 goto MANUAL
GOTO END
rem ============== Manual selection setup ends ==============

:DO
echo.
echo Changing IP...
echo.
netsh interface ip set address name="%Interface%" source=static addr=%IP% mask=%mask%
echo IP address and subnet mask set successfully!
echo.
netsh interface ip set address name="%Interface%" gateway=%gateway% gwmetric=1
echo Gateway address set successfully!
echo.
netsh interface ip set dns name="%Interface%" source=static addr=%DNS1%
echo Primary DNS address set successfully!
echo.
netsh interface ip add dns name="%Interface%" addr=%DNS2% index=2
echo Secondary DNS address set successfully!

:END
pause && exit

[ Last edited by zhqw on 2007-11-6 at 11:28 AM ]
Floor2 hlowd Posted 2007-11-08 16:18
初级用户 Posts 29 Credits 65
Not bad. Support original creation. The code is clear and relatively practical!
Floor3 30082400 Posted 2007-11-08 17:02
新手上路 Posts 1 Credits 2
New here, don't understand, need to study a bit
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023