日省其身,有则改之,无则加勉!

自动修改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
 


« 以基本用户运行IE_全面保护IE免受网络危害视频游泳教学-不会游的看了包你学会 »

发表评论:

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

订阅我的博客 点击订阅网络大杂烩

站内搜索

Powered By Z-Blog 1.8 Arwen Build 90619.Theme by 你认错人了

Copyright © 2009 Netcento.com Inc. All rights reserved||湘ICP备10018482号-1