搜集了一下DOS修改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.24.68
rem dns2 //dns2 为备用DNS
set dns2=202.103.44.150
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.24.68
netsh interface ip add dns "本地连接" addr=202.103.44.150
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
netsh interface ip set dns name="本地连接" source=dhcp
ipconfig /flushdns
可保存记录的IP自动切换软件:
笔记本经常在各个地方走来走去,IP修改比较烦,做了一个IP自动切换工具,可以保存记录。
|