Board logo

标题: 怎么用BAT文件设置IP地址和DNS? [打印本页]

作者: 不得不爱     时间: 2006-9-19 05:07    标题: 怎么用BAT文件设置IP地址和DNS?

怎么用BAT文件设置IP地址、默认网关和DNS服务器地址?
作者: xg911335     时间: 2006-9-19 05:30
好像要读取注册表确定本地连接,在用netsh来修改吧.本人菜鸟。
作者: jzl168     时间: 2006-9-19 12:38
网上一大把,你找 "ghost 自动 ip bat"
都是用netsh 来改ip和其它的,不过很不完善
作者: 不得不爱     时间: 2006-9-19 22:06
我在WIN2000里用用netsh来修改IP它总是提示用指定了无效的接口 本地连接!
作者: 9527     时间: 2006-9-19 22:36
看看你远程注册表的那个服务是不是关掉了,如果关掉是不成的,在看看你网卡的接口名称是否正确!!!
Remote Registry  这个服务如果关闭NETSH命令运行是不成功的
作者: 不得不爱     时间: 2006-9-21 03:26
我把注册表里的HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces下的内容在设置好了IP后导出来,然后在需要时再导入就IP设置好了,不过内容好象多了点!
作者: wang6610     时间: 2006-9-21 05:58
netsh interface ip set address name="本地连接" source=static addr=%IPAddress% mask=255.255.255.0 gateway=192.168.0.1 gwmetric=1
作者: jieok3375     时间: 2006-9-21 23:22
7楼的说法对,若要加DNS  在回第二个时需注意须加 index=2
作者: zouzhxi     时间: 2006-9-22 04:38
@echo off
rem eth //eth 为网卡名称,可在网络连接中查询,如"本地链接"
set eth="本地连接"
rem ip //ip 为你想更改的IP
set ip=*.*.*.*
rem gateway //gateway 为网关地址
set gateway=*.*.*.*
rem netmasks //netmasks 为子网掩码
set netmasks=255.255.255.0
rem dns //dns 为首选DNS
set dns=*.*.*.*
rem dns2 //dns2 为备用DNS
set dns2=*.*.*.*
echo 正在将本机IP更改到: %ip% 请等候...
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 检查当前本机IP:
ipconfig
echo.........................
echo 成功将本机IP更改为%ip%!
pause
close
作者: 不得不爱     时间: 2006-9-22 07:50
楼上的搞的好复杂,一般的在局域网里只有IP地址最后字节地址不同用下面的BAT文件就可以了!
@echo off
set /p a=请输入IP地址最后的一个字节
netsh interface ip set address 本地连接 static 想更改的IP前3个字节.%a% 子网掩码 网关地址 1
netsh interface ip set dns 本地连接 static 首选DNS
netsh interface ip add dns 本地连接 备用DNS
netsh interface ip add dns 本地连接 备用DNS