![]() |
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-02 04:43 |
48,037 topics / 350,122 posts / today 2 new / 48,250 members |
| DOS批处理 & 脚本技术(批处理室) » How to use a BAT file to set the IP address and DNS? |
| Printable Version 4,502 / 9 |
| Floor1 不得不爱 | Posted 2006-09-19 05:07 |
| 超级版主 Posts 2,044 Credits 5,310 From 四川南充 | |
|
How to set the IP address, default gateway, and DNS server address using a BAT file?
|
|
| Floor2 xg911335 | Posted 2006-09-19 05:30 |
| 初级用户 Posts 50 Credits 134 | |
|
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.
|
|
| Floor3 jzl168 | Posted 2006-09-19 12:38 |
| 初级用户 Posts 14 Credits 38 | |
|
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.
|
|
| Floor4 不得不爱 | Posted 2006-09-19 22:06 |
| 超级版主 Posts 2,044 Credits 5,310 From 四川南充 | |
|
I get the error that an invalid interface "Local Area Connection" is specified when I use netsh to modify the IP in WIN2000!
|
|
| Floor5 9527 | Posted 2006-09-19 22:36 |
| 银牌会员 Posts 438 Credits 1,185 From 北京 | |
|
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.
|
|
| Floor6 不得不爱 | Posted 2006-09-21 03:26 |
| 超级版主 Posts 2,044 Credits 5,310 From 四川南充 | |
|
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!
|
|
| Floor7 wang6610 | Posted 2006-09-21 05:58 |
| 银牌会员 Posts 488 Credits 1,246 | |
|
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
|
|
| Floor8 jieok3375 | Posted 2006-09-21 23:22 |
| 中级用户 Posts 130 Credits 282 From 广东 | |
|
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.
|
|
| Floor9 zouzhxi | Posted 2006-09-22 04:38 |
| 中级用户 Posts 177 Credits 430 From 广东深圳 | |
|
@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 |
|
| Floor10 不得不爱 | Posted 2006-09-22 07:50 |
| 超级版主 Posts 2,044 Credits 5,310 From 四川南充 | |
|
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 |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |