日省其身,有则改之,无则加勉!
当前位置:首页系统技巧 - 自动修改IP和DNS的批处理代码

自动修改IP和DNS的批处理代码

代码一:(直接修改IP信息)

@echo off
rem eth //eth 为网卡名称,可在网络连接中查询,如“本地连接”
set eth=本地连接
rem ip //ip 为你想更改的IP
set ip=192.168.1.3
rem gateway //gateway 为网关地址
set gateway=192.168.1.1
rem netmasks //netmasks 为子网掩码
set netmasks=255.255.255.0
rem dns //dns 为首选DNS
set dns=202.103.0.117
rem dns2 //dns2 为备用DNS
set dns2=202.103.24.68
echo 正在将 %eth% 的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
ipconfig /flushdns
echo..............................................................................
echo                        当前计算机IP详情:
echo..............................................................................
ipconfig /all
echo..............................................................................
echo                    成功将 %eth% 的IP更改为: %ip%
echo..............................................................................
pause

代码二:(删除原有的IP信息然后重新填写)

netsh interface ip delete dns "本地连接" addr=all
netsh interface ip add dns "本地连接" addr=202.103.0.117
netsh interface ip add dns "本地连接" addr=202.103.24.68
netsh interface ip add address "本地连接" 192.168.1.3 255.255.255.0
netsh interface ip add address "本地连接" gateway=192.168.1.1 gwmetric=2
ipconfig /flushdns

代码三:(通过DCHP自动获取IP信息)

netsh interface ip set address name="本地连接" source=dhcp
ipconfig /flushdns
 


分享到: 更多
标签:批处理XP技巧系统技巧
分类:系统技巧| 发布:你认错人了| 点击: | 发表时间:2009-9-17
本文链接:http://www.netcento.com/archive/185.html
上一篇:« 以基本用户运行IE_全面保护IE免受网络危害
下一篇:视频游泳教学-不会游的看了包你学会 »

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。