China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-06 12:04
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Batch Command for Automatically Modifying IP, Gateway, and DNS [Original] View 1,518 Replies 2
Original Poster Posted 2007-11-06 11:23 ·  中国 辽宁 营口 联通
新手上路
Credits 18
Posts 6
Joined 2006-03-29 21:50
20-year member
UID 53015
Status Offline
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 ]
Floor 2 Posted 2007-11-08 16:18 ·  中国 河南 郑州 联通
初级用户
Credits 65
Posts 29
Joined 2007-11-03 16:16
18-year member
UID 101592
Gender Male
Status Offline
Not bad. Support original creation. The code is clear and relatively practical!
Floor 3 Posted 2007-11-08 17:02 ·  中国 广东 广州 电信
新手上路
Credits 2
Posts 1
Joined 2007-11-08 16:36
18-year member
UID 102078
Gender Male
Status Offline
New here, don't understand, need to study a bit
Forum Jump: