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-02 05:47
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to use a BAT file to set the IP address and DNS? View 4,503 Replies 9
Original Poster Posted 2006-09-19 05:07 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 2 Posted 2006-09-19 05:30 ·  中国 云南 昆明 电信
初级用户
★★
Credits 134
Posts 50
Joined 2006-03-28 13:50
20-year member
UID 52939
Status Offline
It seems that you need to read the registry to determine the local connection, and then use netsh to modify it. I'm a novice.
Floor 3 Posted 2006-09-19 12:38 ·  中国 广西 钦州 电信
初级用户
Credits 38
Posts 14
Joined 2006-08-16 15:37
19-year member
UID 60649
Gender Male
Status Offline
There are plenty online. You can look for "ghost automatic ip bat". They all use netsh to change IP and others, but it's very imperfect.
Floor 4 Posted 2006-09-19 22:06 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
I get the error that an invalid interface "Local Area Connection" is specified when I use netsh to modify the IP in WIN2000!
Floor 5 Posted 2006-09-19 22:36 ·  中国 北京 联通
银牌会员
★★★
努力做坏人
Credits 1,185
Posts 438
Joined 2006-08-28 12:00
19-year member
UID 61449
From 北京
Status Offline
See if the Remote Registry service is turned off. If it's turned off, it won't work. Also, check if the network card's interface name is correct!!! If the Remote Registry service is turned off, the NETSH command won't run successfully.
我今后在论坛的目标就是做个超级坏人!!!
Floor 6 Posted 2006-09-21 03:26 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
I exported the contents under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces in the registry after setting up the IP, and then imported it when needed to set the IP, but the content seems a bit more!
Floor 7 Posted 2006-09-21 05:58 ·  中国 山东 菏泽 电信
银牌会员
★★★
Credits 1,246
Posts 488
Joined 2003-11-11 00:00
22-year member
UID 12699
Gender Male
Status Offline
netsh interface ip set address name="Local Area Connection" source=static addr=%IPAddress% mask=255.255.255.0 gateway=192.168.0.1 gwmetric=1
Floor 8 Posted 2006-09-21 23:22 ·  中国 广东 东莞 电信
中级用户
★★
Credits 282
Posts 130
Joined 2006-09-20 22:25
19-year member
UID 63201
From 广东
Status Offline
What the user said on the 7th floor is correct. If you want to add DNS, when replying to the second one, you need to pay attention to adding index=2.
Floor 9 Posted 2006-09-22 04:38 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
@echo off
rem eth //eth is the name of the network card, which can be queried in Network Connections, such as "Local Area Connection"
set eth="Local Area Connection"
rem ip //ip is the IP you want to change
set ip=*.*.*.*
rem gateway //gateway is the gateway address
set gateway=*.*.*.*
rem netmasks //netmasks is the subnet mask
set netmasks=255.255.255.0
rem dns //dns is the preferred DNS
set dns=*.*.*.*
rem dns2 //dns2 is the alternate DNS
set dns2=*.*.*.*
echo Changing the local IP to: %ip%, please wait...
rem
if %gateway%==none netsh interface ip set address %eth% static %ip% %netmasks% %gateway% > nul
if not %gateway%==none netsh interface ip set address %eth% static %ip% %netmasks% %gateway% 1 > nul
if %dns%==none netsh interface ip set dns %eth% static %dns%> nul
if not %dns%==none netsh interface ip set dns %eth% static %dns%> nul
if %dns2%==none netsh interface ip add dns %eth% %dns2%> nul
if not %dns2%==none netsh interface ip add dns %eth% %dns2% 2> nul
echo.........................
echo Checking current local IP:
ipconfig
echo.........................
Successfully changed the local IP to %ip%!
pause
close
Floor 10 Posted 2006-09-22 07:50 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
The upstairs made it too complicated. Generally, in a local area network where only the last byte of the IP address is different, you can use the following BAT file!
@echo off
set /p a=Please enter the last byte of the IP address
netsh interface ip set address "Local Area Connection" static The first three bytes of the IP to be changed.%a% Subnet mask Gateway address 1
netsh interface ip set dns "Local Area Connection" static Preferred DNS
netsh interface ip add dns "Local Area Connection" Alternate DNS
netsh interface ip add dns "Local Area Connection" Alternate DNS
Forum Jump: